Object variable or with block not set error shows when running from vba not from macro button

QuestionBaker

Board Regular
Joined
Apr 12, 2019
Messages
106
Office Version
  1. 365
Platform
  1. Windows
I use find method to find column number.
If I run the code from a button that is present in the sheet, the code runs fine
If I run the same code via visual basic, it throws an error saying object variable or with block not set.
Has anyone else encountered this type of problem before?
 

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.
It might pay to post the code you are using.
 
Upvote 0
The actual code is way too big but the error was occurring on the following line
VBA Code:
j_start = deliver.Range("A1:XFD1048576").Find(what:=CDate("1/" & MonthName(DatePart("m", next_stone)) & "/" & DatePart("yyyy", next_stone))).Column
but the error has stopped occurring now. IIRC the only changes I did was add some spaces where I define public variables.
Plus, I recovered an older version where the error was not occurring and updated the code over there while checking line.
The problem is resolved, but I don't know what led to the solution.
 
Upvote 0
Solution
Glad to hear that you resolved the issue.
But I would consider making changes to your ranges !!
If you have a few of these Range("A1:XFD1048576") it could slow down you code significantly.
Surely you aren't using EVERY cell in the sheet !!
Look at changhing to something like UsedRange or CurrentRegion instead
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,195
Members
449,072
Latest member
DW Draft

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