VBA to Paste data into worksheet specified by user

JKast

New Member
Joined
Jul 26, 2011
Messages
21
Hi all,

I want to copy a range of data from one worksheet, and paste it into another worksheet. The worksheet it will be pasted into should be specified by the user. I'm trying to do this by using an inputbox where the user can enter the name of the worksheet he/she would like the data pasted into. This is the code I have so far.

I set sheetName as an integer variable because the names of the worksheets that the data can be pasted into are 1-31. (Representing Days of the month)

I don't think I'm referencing the variable correctly though. I'm new to VBA, I'd appreciate any help.

Sub Data()

Dim sheetName As Integer
Application.ScreenUpdating = False

Range("DataEntry").Copy
sheetName = InputBox("Please enter current day of the month", sheetName)
Worksheets("sheetName").Range("a1:z600").PasteSpecial Paste:=xlPasteValues

End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try

Code:
Sub Data()
Dim sheetName As String
sheetName = InputBox("Please enter current day of the month")
Application.ScreenUpdating = False
Range("DataEntry").Copy
Worksheets(sheetName).Range("A1").PasteSpecial Paste:=xlPasteValues
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Another approach would be to let the user select the worksheet with the mouse.

Code:
Dim uiRange as Range
Dim uiSheet as Worksheet

On Error Resume Next
    Set uiRange = Application.InputBox("Select a sheet with the mouse", type:=8)
On Error Goto 0

If uiRange is Nothing then
    Rem cancel pressed
Else
    Set uiSheet = uiRange.Parent
End If

Hmm...when I get home I need to test
Code:
MsgBox TypeName(Application.InputBox("select", type:=10))
when the user clicks a sheet tab and presses OK without clicking on a cell.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,508
Messages
6,179,188
Members
452,893
Latest member
denay

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