copy from one worksheet, paste on another

Pondridge

New Member
Joined
Sep 17, 2012
Messages
6
Why doesn't this work?

Sub DuesSheet()
Dim vLine As String * 3
vLine = InputBox("Enter Line Number", Value, "2-139")
Sheets("Members").Select
Range("A" & vLine).Select
Selection.Copy
Sheets("Form").Select
Range("F30").Select
ActiveSheet.Paste
End Sub

I'm placing a number in a input box, then going to the members sheet, selecting cell A & the line number, copying contents, then going to the form sheet, cell F30, to paste what was copied. It seems like a simple task, but has been driving me crazy. 14 years since I wrote code and was a novice back then. Please help.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi Pondridge,

Must say I've not seen the bolded part of this Dim vLine As String * 3. What is it for?

In any case this should do what you're after:

VBA Code:
Option Explicit
Sub DuesSheet()

    Dim vLine As String

    vLine = InputBox("Enter Line Number:")
   
    If Len(vLine) = 0 Then Exit Sub 'User clicked <Cancel> or made no entry
   
    Application.ScreenUpdating = False
        Sheets("Members").Range("A" & CLng(vLine)).Copy Destination:=Sheets("Form").Range("F30")
    Application.ScreenUpdating = True

End Sub

Regards,

Robert
 
Upvote 0
Seems to work ok for me, unless you hit "cancel". Your code could be simplified a bit.

VBA Code:
Sub DuesSheet()
    Dim vLine As String
    vLine = InputBox("Enter Line Number", Value, "2-139")
    If IsNumeric(vLine) And Val(vLine) >= 2 And Val(vLine) <= 139 Then
        Sheets("Members").Range("A" & vLine).Copy Sheets("Form").Range("F30")
    Else
        MsgBox "Error - Entered value is outside of valid range", vbOKOnly Or vbCritical, "Error"
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,730
Members
448,987
Latest member
marion_davis

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