UsedRange Property

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Returns a Range object that represents the used range on the specified worksheet.

expression.UsedRange

expression   Required. An expression that returns a Worksheet object.

Example

This example adjusts the row height and column width for the used range on the active worksheet to fit the data contained in the range.

  Sub AutoFitSpreadsheet()

   Dim rngUsedRange

   ' Set a variable tot he used range in the active sheet.
   Set rngUsedRange = Spreadsheet1.ActiveSheet.UsedRange

   ' Autofit the rows.
   rngUsedRange.AutoFitRows

   ' Autofit the columns.
   rngUsedRange.AutoFitColumns

End Sub