Trouble with worksheet variable

davidam

Active Member
Joined
May 28, 2010
Messages
497
Office Version
  1. 2021
Platform
  1. Windows
Hello All,
I am using the following to set a worksheet variable

Code:
Public thisBook As Workbook
Public thisSheet As Worksheet
 
Set thisBook = ThisWorkbook
Set thisSheet = thisBook.Worksheets("Data Input")
Call Save_Case

Later I try to use it:

Code:
Dim testval As Integer
testval = thisSheet.Range("Q376").Value
I get run time error: Object variable or With block variable not set. This one I do not understand at all. I set the variables as above and then try to use them in the procedure called Save_Case all in the same module...is it perhaps something to do with using ThisWorkbook?
 
I'd suggest Excel VBA Programming for Dummies by Walkenbach - any version. Excellent introduction. You could in fact read or use any introduction to programming or any intro tutorial for any programming language. Passing arguments is a general concept that applies to any programming language. In other words, you probably need a Programming 101 course.

A good way to learn VBA is also to know and use your debugging skills - you can walk through the program line by line and literally watch what the variables are doing as you step through the code:
http://krgreenlee.blogspot.com/2006/04/programming-excel-vba-debugging-for.html
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,225,156
Messages
6,183,230
Members
453,152
Latest member
ChrisMd

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