Dim As Worksheet

Heather_Llo

New Member
Joined
Feb 16, 2018
Messages
17
So I've done a bit of research on Dim As Worksheet and what it means, but I'm still not entirely confident with it. As I understand it renames a sheet based on its number (such as Sheet1, Sheet2, Sheet3, etc.) to a value that you specify so that you can reference it from the new value. I understand that it can also define a destination for a function.

I am needing to know more about this function because it may affect what I am doing in my newest worksheet.

This is the Dim As Worksheet function I have in it currently:
'Rename sheets Dim NextRow As Long
Dim wsPaste As Worksheet: Set wsPaste = Sheets("AMPaste")
Dim wsCurrent As Worksheet: Set wsCurrent = Sheets("AMCurrent")
As I understand in this code (which someone wrote for me), it is taking the functions "wsPaste" and "wsCurrent" and applying them to only affect "AMPaste" and "AMCurrent". Is this correct? I am worried about it because I am wanting to copy and paste the code out, editing the function names and sheet names, to use it on a different sheet in the workbook, but I don't know if they will override each other.

Thanks!
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
You should be aware that "wsPaste" and "wsCurrent" are variables and not functions. The "Set" statement assigns a particular sheet to that variable so
Code:
Dim wsPaste As Worksheet: Set wsPaste = Sheets("AMPaste")
Dim wsCurrent As Worksheet: Set wsCurrent = Sheets("AMCurrent")
assigns the "AMPaste" sheet to the variable "wsPaste" and assigns the "AMCurrent" sheet to the variable "wsCurrent". If you change the variable name and assign it to a different sheet, that will not be a problem. I hope this makes sense.
 
Upvote 0
You should be aware that "wsPaste" and "wsCurrent" are variables and not functions. The "Set" statement assigns a particular sheet to that variable so
Code:
Dim wsPaste As Worksheet: Set wsPaste = Sheets("AMPaste")
Dim wsCurrent As Worksheet: Set wsCurrent = Sheets("AMCurrent")
assigns the "AMPaste" sheet to the variable "wsPaste" and assigns the "AMCurrent" sheet to the variable "wsCurrent". If you change the variable name and assign it to a different sheet, that will not be a problem. I hope this makes sense.
Yes, that makes sense. Thank you.
 
Upvote 0

Forum statistics

Threads
1,225,741
Messages
6,186,763
Members
453,370
Latest member
juliewar

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