Hello,
I need to create a code that will copy the data to the last cell and paste to another workbook in one sheet. The code I have work well when there is two or more rows of data and it does not work when there is only one row of data in worksheet. How do I write a code that will not break when there is a sheet with one row of data?
Thank you in advance!!
I need to create a code that will copy the data to the last cell and paste to another workbook in one sheet. The code I have work well when there is two or more rows of data and it does not work when there is only one row of data in worksheet. How do I write a code that will not break when there is a sheet with one row of data?
Thank you in advance!!
VBA Code:
Dim M As Long
Dim LastRow As Long
Dim CopyCell As Variant
Dim CopyR As Long
Dim SearchR As Range
Dim wb As Workbook
Set wb = ActiveWorkbook
wb.Activate
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
Workbook("Book 1.xlms").Activate
Sheets(M + 1).Activate
Set SearchR = Range("A:A").Find(What:="*", LookIn:=xlValues, lookat:=xlWhole)
Set CopyR = SearchR.Offset(3, 0)
Range(CopyR, CopyR.End(xlDown).End(xlToRight)).Copy
Cells(LastRow + 1, 1).Select
ActiveCell.PasteSpecial (xlPasteValues)