Object Variable or With Block Variable not set

Yorke

New Member
Joined
Nov 29, 2021
Messages
19
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I'm having problems with a simple piece of code which suddenly stopped working, and I don't recall changing anything which has caused this to break. The code says 'object variable or with block variable not set', but I have set the dim above. Here is my code:

Dim ThisWorkBook As Workbook
Dim Cell2 As Range

For Each Cell2 In ThisWorkBook.Worksheets("Data").Range("Z91:Z186") 'Debug highlights this line

'Long piece of additional code

Next Cell2

Thanks in advance :)
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Note that "ThisWorkbook" is NOT a variable, so you should NOT declare it in your code (if you aren't setting it, it is not a variable).
It is a pre-defined object in VBA.

Some things to check:
1. Is the sheet still named "Data", or has it been renamed?
2. Is the "Data" sheet visible?
3. Is the "Data" sheet protected?
4. Are any of the cells in the range Z9:Z186 locked/protected, hidden, or merged?
5. Do any of the cells in the range Z9:Z186 contain errors?
 
Upvote 0
Solution
Hi Joe,
Thank-you for your help!
I simply removed the dimensions from the workbooks.
Thanks again!
 
Upvote 0

Forum statistics

Threads
1,223,948
Messages
6,175,579
Members
452,653
Latest member
craigje92

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top