Hi. I need some help with my macro.
I have 2 sheets. Sheet 1 is my working paper with more than 20 columns and Sheet 2 is my database.
Whenever I enter some data in my sheet 1 to do some calculations, I want to save the values to my database (Sheet 2) to its specified columns. The problem is the number of rows in my sheet 1 always vary. How can I copy my data from row 2 up to last used row and save to it to the last available row in my database.
Below is the code I am using:
Sub SavePayroll
Dim lastrow as long
Dim erow as long
lastrow = sheet1.cells(rows.count,5).end(xlup).row 'I used column 5 or E to be the basis of finding the last used row
erow = sheet2.cells(rows.count,1).end(xlup).row + 1
For i = 2 to lastrow
Sheet2.cells(erw, 1)= range("B" & i)
Sheet2.cells(erw, 2)= range("C" & i)
Next
End Sub
Using the above code, only the value of the last row was saved to my database. Thank you so much for the help.
I have 2 sheets. Sheet 1 is my working paper with more than 20 columns and Sheet 2 is my database.
Whenever I enter some data in my sheet 1 to do some calculations, I want to save the values to my database (Sheet 2) to its specified columns. The problem is the number of rows in my sheet 1 always vary. How can I copy my data from row 2 up to last used row and save to it to the last available row in my database.
Below is the code I am using:
Sub SavePayroll
Dim lastrow as long
Dim erow as long
lastrow = sheet1.cells(rows.count,5).end(xlup).row 'I used column 5 or E to be the basis of finding the last used row
erow = sheet2.cells(rows.count,1).end(xlup).row + 1
For i = 2 to lastrow
Sheet2.cells(erw, 1)= range("B" & i)
Sheet2.cells(erw, 2)= range("C" & i)
Next
End Sub
Using the above code, only the value of the last row was saved to my database. Thank you so much for the help.