Saturday, April 20, 2019

VBA Range Run-time error 91 Object variable or With block variable not set

Run-time error 91;Run-time error 91 Object variable or With block variable not set;Run-time error 91 while defining Range;VBA Range Run-time error 91 Object variable or With block variable not set;create 5 seconds before unload userform


Error:


I encountered the below error when I try to define a range variable.

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


Code:

Dim changedRange As Range

changedRange = Sheets(sheetName).ListObjects(table).DataBodyRange --Error on this line

Solution:


Needed to use "Set", because I had defined changedRange as Range - and this is an Object ;)
Set changedRange = Sheets(sheetName).ListObjects(table).DataBodyRange

That solved the issue.


No comments:

Post a Comment