currently have book1 and book2.
Need to transfer data from book1 sheet1 cells a2:a7 to book2 sheet1, in the next available row then close and save changes in book 2 and go back to book1, currently have code below which worked before when I had a MAcro button on the sheet.
Now got a button in a userform, do I need to do anything different
Need to transfer data from book1 sheet1 cells a2:a7 to book2 sheet1, in the next available row then close and save changes in book 2 and go back to book1, currently have code below which worked before when I had a MAcro button on the sheet.
Now got a button in a userform, do I need to do anything different
Code:
NewName = ActiveWorkbook.Name
Workbooks.Open "C\Book2.xls", , , , "password"
If ActiveWorkbook.ReadOnly = True Then
MsgBox "Book2 is being used. Please wait.... , , "Save Record"
ActiveWindow.Close
Exit Sub
Else
Workbooks(NewName).Activate
Sheets("Sheet1").Activate
Range("a2:a7").Copy
Workbooks("Book2.xls").Activate
Sheets("Sheet1").Activate
Range("A3").Activate
RowNo = 0
Start:
If IsEmpty(ActiveCell.Offset(RowNo, 0)) Then
ActiveCell.Offset(RowNo, 0).PasteSpecial xlPasteValues
ActiveCell.Offset(RowNo, 2).Value = RowNo + 1
Else
RowNo = RowNo + 1
GoTo Start
End If
Workbooks("Book2.xls").Close Savechanges:=True
Workbooks(NewName).Activate
CutCopyMode = False
ThisWorkbook.Activate