Coldfire46
New Member
- Joined
- Aug 6, 2015
- Messages
- 17
Hi all,
I'm writing some code (see below) to add to a command button on a worksheet and seem to be having some trouble. All I want to do is select a row a data and copy it from one workbook into the first empty row of a worksheet in a different workbook.
The code seems to work when i = 2, but seems to fall down when it comes to i = 3 etc; any advice on where I'm going wrong would be really useful.
I'm writing some code (see below) to add to a command button on a worksheet and seem to be having some trouble. All I want to do is select a row a data and copy it from one workbook into the first empty row of a worksheet in a different workbook.
The code seems to work when i = 2, but seems to fall down when it comes to i = 3 etc; any advice on where I'm going wrong would be really useful.
Code:
Private Sub CommandButton2_Click()
Application.ScreenUpdating = False
Set wsID = ThisWorkbook.Worksheets("Export to Auto-Loader")
LastRow = wsID.Range("A1:A" & Rows.Count).Find(what:="*", searchdirection:=xlPrevious, after:=[A1]).Row
For i = 2 To LastRow
wsID.Range(Cells(i, 1), Cells(i, 20)).Select
Selection.Copy
Let Path = ThisWorkbook.Path
Workbooks.Open Filename:=Path & "\ProPricerImportSheet.xlsm"
p = Worksheets.Count
For q = 1 To p
If ActiveWorkbook.Worksheets(q).Name = "Task Auto Import" Then
Worksheets("Task Auto Import").Select
End If
Next q
EmptyRow = ActiveSheet.Range("A1:A" & Rows.Count).Find(what:="*", searchdirection:=xlPrevious, after:=[A1]).Row
ActiveSheet.Cells(EmptyRow, 1).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Next i
Application.ScreenUpdating = True
End Sub