I'd like to ask how to add, copy and display next to another sheet. For example, I have a data in column A on rows 1 to 4 and a button named save inside sheet 1. When I enter the save button, the data in sheet 1 will copy to sheet 2 on same column and row.
When I have new data, it will add up to to row 2 from row1 under sheet2.
The data should be like this:
Sheet1
Name Address Age Birthdate
Sheet2:
Row1:Name Row1:Address Row1:Age Row1: Birth date;
Row2:Name Row2:Address Row2:Age Row2: Birth date
Answer
As you demanded I've set the Row 2 of Sheet 1 as Data Entry Row, every time you need to write data in Row 2 and Excel will add new record into Sheet 2 after existing record.
Then after Excel will Delete the new record from Row 2 in Sheet 1 and place the Cell Pointer on Cell A2, so that you can write new record.
Private Sub CommandButton2_Click()
Application.ScreenUpdating = False
Dim copySheet As Worksheet
Dim pasteSheet As Worksheet
Set copySheet = Worksheets("Sheet1")
Set pasteSheet = Worksheets("Sheet2")
copySheet.range("A2:D2").Copy
pasteSheet.Cells(Rows.count, 1).End(xlUp).offset(1, 0).PasteSpecial
xlPasteValues
Application.CutCopyMode = False
Worksheets("Sheet1").Rows(2).EntireRow.Delete
Range("A2").Select
Application.ScreenUpdating = True
End Sub
NB: In this sample code I've used Row 2 for Data Entry, if you feel you can alter it.
No comments:
Post a Comment