another way to do Dim a worksheet?

birdieman

Well-known Member
Joined
Jan 13, 2016
Messages
551
I am still relatively new to VBA so my question may not be stated with correct words. One of my worksheets is labeled ufd. Is this the correct way to set it up to be able to then refer/use it in code?
Code:
Dim ufd As Worksheet
Set ufd = Sheets("ufd")

The above works fine, but I wondering if the word "set" is correct because I have begun to have some Excel crashing problems and am checking all the little stuff. One of the Excel -type errors is "do not set the value of a microsoft object......." This may have nothing to do with my code above but was checking everything.

So, back to the question: Is the above the correct way to Dim a worksheet, or is there a simpler/better/shorter way?
thanks
 

Some videos you may like

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,056
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Yes that is correct.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
55,882
Office Version
  1. 365
Platform
  1. Windows
Yes, that is correct.
When setting variables equal to objects (like workbooks, worksheets, and ranges), you use "Set".
 

Watch MrExcel Video

Forum statistics

Threads
1,122,215
Messages
5,594,883
Members
413,947
Latest member
gizmolucy

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
Top