How to use a cell value as an input for a sheet name in VBA

Nicholas3108

New Member
Joined
May 24, 2016
Messages
3
I am trying to copy data from one worksheet to another using VBA. This is the code I currently have:

Sub sbCopyRangeToAnotherSheet()
Sheets("Active Worksheet, A2").Range("Q1:S52").Copy Destination:=Sheets("Analyst").Range("B3")
End Sub

I am trying to link the sheet name in my VBA code to the value/text in cell A2 of the active worksheet (I am going to have a dropdown of the different names of the worksheets within the workbook from where I want to take data).

Each time I run the macro I get the error code "Subscript out of range".

Would greatly appreciate some assistance on this.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try this.
Code:
Sub sbCopyRangeToAnotherSheet()
Dim strSheet As String

    strSheet = ActiveSheet.Range("A2").Value
    Sheets(strSheet).Range("Q1:S52").Copy Destination:=Sheets("Analyst").Range("B3")

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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