VBA allow user to choose which Worksheet to target

GuyGadois

Active Member
Joined
Jan 12, 2009
Messages
344
Office Version
  1. 2019
Platform
  1. Windows
I have the following simple Macro. The problem is now I want the user to pick which Sheet they want to paste the information on. I have Account_1, Account_2, Account_3, etc. tabs and there may be more the user adds so it is never going to be predetermined. I would like for the user to pick from a list when the Macro starts and it pastes the info in the chosen worksheet, range A4. Is this possible?

Sub MoveData()
Call ShowRows
Selection.Copy
Application.Goto ActiveWorkbook.Sheets("Account 1").Range("A4")
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Call HideRows
End Sub

Cheers,

Guy
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Does this help?
Code:
Sub MoveData()
  Dim v As Variant
  Dim GoSht As Worksheet
  Dim GoWB As Workbook
  Dim A As String
  
  On Error Resume Next                    'Have the user point to the right sheet
  Set v = Application.InputBox("Find the sheet where you want to copy the data", "Activate Sheet", Type:=8)
  On Error GoTo 0
  
  If v Is Nothing Then Exit Sub
  A = v.Parent.Parent.Name                    'Save the workbook and worksheet into vars
  Set GoWB = Workbooks(A)
  Set GoSht = Sheets(v.Parent.Name)
  
  Call ShowRows
  Selection.Copy
  GoSht.Range("A4").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
  
  Call HideRows
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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