Trading Post LLC
Trading Post LLC

Reputation: 53

What object should be referenced to use the UsedRange property?

I am using the UsedRange property.

I get

Run-time error '91': Object variable or With block variable not set.

I have checked here and Googled it. I have followed syntax examples.

I deleted the temp files that caused an issue with it back in 2014.

The below code I also tried with totalRange = UsedRange.

Dim totalRange As Range
totalRange = VBA.UsedRange
Set totalRange = totalRange.Offset(1, 0).Resize(totalRange.Rows.Count - 1, _
                                               totalRange.Columns.Count)

What it needs to do is select the total range of data, minus the header.

Upvotes: 1

Views: 129

Answers (1)

Pᴇʜ
Pᴇʜ

Reputation: 57683

Since totalRange is of type Range it is an object and objects have to use Set and .UsedRange must refer to a worksheet in a specific workbook.

Set totalRange = ThisWorkbook.Worksheets("Sheet1").UsedRange

Upvotes: 3

Related Questions