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

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
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,223,896
Messages
6,175,264
Members
452,627
Latest member
KitkatToby

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