How to use a sheet name in a cell to reference a sheet in a macro?

link710

New Member
Joined
Feb 7, 2015
Messages
4
I have a list of sheet names and a drop down list of those sheet names in a cell. I then want a macro that will take whatever sheet name is selected from the drop down list and select that sheet and create a new copy of it in the current workbook.

Probably super simple but I can't seem to figure out how to reference the sheet name as a value in a cell:



' copyandpastesheet Macro
'


'
Sheets("THIS IS WHERE I WANT TO REFERENCE A CELL THAT HOLDS A SHEET NAME").Select
Cells.Select
Selection.Copy
Sheets.Add After:=Sheets(Sheets.Count)
Cells.Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Range("A1").Select
End Sub

Please let me know if you think you have a solution for my novice nature, thanks.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi link710,

Welcome to MrExcel!!

The following assumes the drop-down is in cell A1 of Sheet1 (change to suit):

Code:
Option Explicit
Sub Macro2()

    Dim strMySheet As String
    
    strMySheet = Sheets("Sheet1").Range("A1")

    Sheets(strMySheet).Select

End Sub

HTH

Robert
 
Upvote 0
Assuming that A2 in Sheet1 contains your drop down list, maybe something like this...

Code:
Sub test()

    Sheets(Sheets("Sheet1").Range("A2").Value).Cells.Copy
    
    Sheets.Add After:=Sheets(Sheets.Count)
    
    With Range("A1")
        .PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        .PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    End With
    
    Range("A1").Select
 
End Sub

Hope this helps!
 
Last edited:
Upvote 0
That looks like it will work perfectly. I'll be able to test it out tomorrow at my shop. Thanks so much already. My first post on my first forum.

Thanks,
Nick
 
Upvote 0
Couldn't wait until tomorrow, just mocked up a sheet to test it out and it works great! Thanks!

Aussie, aussie, aussie!
 
Upvote 0
Just tried this out and it works great! Thanks! Super fast help, I might actually be able to get this project done before the end of the weekend!
 
Upvote 0
Aussie, aussie, aussie!

Oi, Oi Oi!!!

Thanks for the feedback and I'm glad to hear it's working. Did you try Domenic's suggested solution as it looks pretty nifty?

You should also consider building in some error trapping i.e. if no selection is made then alert the user of such or if the selection isn't actually a worksheet in the workbook (perhaps because it's been deleted or renamed after the drop-down was set).

Regards,

Robert
 
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,150
Members
448,552
Latest member
WORKINGWITHNOLEADER

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