how to refer a newly created worksheet?

Chiwidan

New Member
Joined
Apr 19, 2020
Messages
15
Office Version
  1. 2010
Platform
  1. Windows
Hi everyone,

Hi from Middle Earth again.

I am stuck in something probably extremely easy:

VBA Code:
'Creates Invoice Worksheet

    sheet_name = shMacros.Range("A24:A33").Cells(i, 1).Value
    Sheets.Add.Name = sheet_name
    
'Copy data from InvSample to Invoice Sheet

    Sheets("sheet_name").Select
    Cells.Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With

Stops in the

Sheets("sheet_name").Select

line...

How do you refer a newly automatically created worksheet if the name will be changing? I was thinking the variable "sheet_name" will be the one to "call" when you want to go to that worksheet?


What am I missing?

Dan
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Hi,

I tried your code and it did not add in a sheet called 'sheet_name'. So I added in "" around the new sheet name and it worked. Managed to select the sheet and change the cells fill to white.

VBA Code:
Sheets.Add.Name = "sheet_name"

It was looking for a sheet that was not there so failed from the looks of things

Steven
 
Upvote 0
Sheets("sheet_name").Select

Remove the quote marks from that line
 
Upvote 0
You're welcome. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,849
Members
449,051
Latest member
excelquestion515

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