supermom28115
New Member
- Joined
- May 9, 2022
- Messages
- 43
- Office Version
- 365
- Platform
- Windows
I found this thread and wanted to ask about the use of a variable to hold the sheet name.
Is this the way the code should be written when using variables for objects?
I was under the impression that I should be using this code:
I ask because this is not working in my code and I can not figure out why it will not work. I have tried multiple variations of this code; ie long hand the workbook name within the set code, using worksheet, sheet, sheets, using the index for the sheet. I have even tried changing the variable name in case the ws was inappropriate. I continually get the same ws1= Nothing, object variable or with variable not set error.
So how am I supposed to declare and set a variable correctly for my workbook and worksheets to use in my code?
Is this the way the code should be written when using variables for objects?
I was under the impression that I should be using this code:
VBA Code:
Dim ws1 As Worksheet
Set ws1 = ThisWorkbook.Worksheets("Sheet 1")
So how am I supposed to declare and set a variable correctly for my workbook and worksheets to use in my code?
ThisWorkbook.Sheets with variable
Hi folks, I am trying to create a generic code that could use the sheet name, which is stored in a cell. Dim wsName As String Dim ws As Worksheet Dim targetCell As Range ' Set the target cell (N3 in this case) for the active sheet Set targetCell = ActiveSheet.Range("N3")...
www.mrexcel.com