Runtime error 1004

L

leejen87

PLease help!

This has been racking my brains for days!

I am trying to select a cell from which to start a selection copy.
however i keep getting the runtime error on the Range line

where, o where am i going wrong?!?!?!?



Private Sub CommandButton1_Click()
OrderNumber = InputBox("Enter CPL#")
If OrderNumber = "" Then
End If

Receiptfile = "CPL #" & OrderNumber & ".xls"
Workbooks.Open Filename:="C:\Documents and Settings\a\My Documents\" &
Receiptfile
ActiveSheet.Name = Receiptfile


Workbooks.Open Filename:= _
"C:\Documents and Settings\a\My Documents\Entry Build.xls"
Windows("Entry Build.xls").Activate
Sheets("Entry Build").Select
Sheets("Entry Build").Copy After:=Workbooks(Receiptfile).Sheets(1)


Sheets(Receiptfile).Activate
Range("A12").Activate THIS IS THE CULPRIT LINE OF CODE!!!
Range(Selection, Selection.End(xlToRight)).Select
Range("A12:I350").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Entry Build").Select
ActiveWindow.SmallScroll Down:=-3
Range("A5").Select
ActiveSheet.Paste
 
T

Tom Ogilvy

Private Sub CommandButton1_Click()
OrderNumber = InputBox("Enter CPL#")
If OrderNumber = "" Then
exit sub
End If

Receiptfile = "CPL #" & OrderNumber & ".xls"

set bk1 = Workbooks.Open( Filename:= _
"C:\Documents and Settings\a\My Documents\" & Receiptfile
ActiveSheet.Name = Receiptfile


set bk2 = Workbooks.Open Filename:= _
"C:\Documents and Settings\a\My Documents\Entry Build.xls"


bk2.Sheets("Entry Build").Copy After:=bk1.Sheets(1)


With bk1.Sheets(Receiptfile)
.Range("A12:I350").Copy bk1.Sheets("Entry Build").Range("A5")
End With
End Sub
 
T

Tom Ogilvy

Cleaned up a couple of typos:


Private Sub CommandButton1_Click()
Dim bk1 As Workbook, bk2 As Workbook
OrderNumber = InputBox("Enter CPL#")
If OrderNumber = "" Then
Exit Sub
End If

Receiptfile = "CPL #" & OrderNumber & ".xls"

Set bk1 = Workbooks.Open(Filename:= _
"C:\Documents and Settings\a\My Documents\" & _
Receiptfile)
ActiveSheet.Name = Receiptfile


Set bk2 = Workbooks.Open(Filename:= _
"C:\Documents and Settings\a\My Documents" & _
"\Entry Build.xls")


bk2.Sheets("Entry Build").Copy _
After:=bk1.Sheets(1)


With bk1.Sheets(Receiptfile)
.Range("A12:I350").Copy bk1.Sheets( _
"Entry Build").Range("A5")
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top