How to have user to input destination sheet

LLT

Board Regular
Joined
Nov 4, 2009
Messages
51
Dear Expert,

Currently I have hardcoded the destination sheets to be "Cashbook" whereby the data will be copied to. If I need user to input the destination sheet, how do I code the macro?

Dim lr As Long, r As Long
Dim ws As Worksheet
Dim wsName As String
Dim wsDest As String

wsName = Sheets("Instruction").Range("H4")

On Error Resume Next
Set ws = Sheets(wsName)

On Error GoTo 0
If ws Is Nothing Then
MsgBox wsName & " is not a valid sheet name for this workbook"
Else
With ws

UsedRange.Copy Destination:=Sheets("Cashbook").Range("A" & Rows.Count).End(xlUp).Offset(1)
End With

End If
End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Try something like this...

Code:
With ws
    UsedRange.Copy Destination:=[COLOR="Red"].[/COLOR]Range("A" & Rows.Count).End(xlUp).Offset(1)
End With

Or just this...
Code:
    UsedRange.Copy Destination:=[COLOR="Red"]ws.[/COLOR]Range("A" & Rows.Count).End(xlUp).Offset(1)
 
Last edited:
Upvote 0
Hi

I would like to explain my code first. "wsName=Sheets("Instruction").Range("H4")" is referring to the sheet in which the data will be copied from.

And then I want it to be copied to "Cashbook" sheet. This is where I have hard coded the destination sheet. But if now if I want to replace the "Cashbook" sheet to allow user to input the name of the sheet that they name. How to go about doing it.

Thanks so much!!


[Dim lr As Long, r As Long
Dim ws As Worksheet
Dim wsName As String
Dim wsDest As String

wsName = Sheets("Instruction").Range("H4")

On Error Resume Next
Set ws = Sheets(wsName)

On Error GoTo 0
If ws Is Nothing Then
MsgBox wsName & " is not a valid sheet name for this workbook"
Else
With ws

UsedRange.Copy Destination:=Sheets("Cashbook").Range("A" & Rows.Count).End(xlUp).Offset(1)
End With

End If
End Sub <!-- / message -->]
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,712
Members
452,939
Latest member
WCrawford

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