VBA allow user to choose which Worksheet to target

GuyGadois

Active Member
Joined
Jan 12, 2009
Messages
342
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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
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,216,102
Messages
6,128,852
Members
449,471
Latest member
lachbee

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