Macro to ask user which sheet to copy from

Vkackley3300

New Member
Joined
Apr 27, 2020
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi. I need a macro to copy data data from another worksheet in the same workbook into the current active worksheet.

I would like to have a dialog box pop up that asks the user to input the sheet name they want to copy from. If they put in an invalid sheet name, it would prompt them that it was an invalid sheet name and to try again or give them the option to cancel. Once they enter a valid sheet name, the macro would need to copy range A1:X76 of that sheet and paste it into the current worksheet.

I found the code below posted in response to another question. It works pretty well except I do not want the data copied into "Copy Data". I would like the data copied into the active worksheet when the macro is initiated. I have tried to modify the code below but I cannot figure it out.

Any help would be appreciated.

Sub copy_data()
Dim response As String, ws As Worksheet
Dim sht As String
100:
response = Application.InputBox("Select a cell in the worksheet to copy from", "Select", Type:=2)
On Error Resume Next
If response = "False" Then Exit Sub
Set ws = Sheets(response)
On Error GoTo 0
If ws Is Nothing Then
MsgBox "Invalid sheet name, enter again or Cancel to exit."
response = ""
GoTo 100
End If
ws.Range("A1:X76").Copy Sheets("Copy Data").Range("A1")
End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Cange this line
ws.Range("A1:X76").Copy Sheets("Copy Data").Range("A1")
into this
VBA Code:
ws.Range("A1:X76").Copy ActiveSheet.Range("A1")
 
Upvote 0
Hi GWteB, I am very sorry for my delayed response. Your correction above worked perfect. Thanks for the coaching!
 
Upvote 0
You are welcome and thanks for letting me know. Welcome to this board!
 
Upvote 0

Forum statistics

Threads
1,215,006
Messages
6,122,666
Members
449,091
Latest member
peppernaut

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