I want to be able to press a button to copy some data across from sheet "Data Entry" to the first blank row in another sheet "Database".
However, if the first column is blank, I don't want that row of data to be copied. Also, sometimes the "Data Entry" sheet may have 4 rows of data, whilst sometimes it may have 5, 6, 7 or 8.
I've attached screenshots below.
The code I'm using so far is not giving any error, but nothing seems to be happening, either.
Private Sub CommandButton1_Click()
Dim cl As Range
For Each cl In Sheet2.Range("A8:A23")
If Not IsEmpty(ActiveCell.Value) Then
Range("A" & ActiveCell.Row & ":R" & ActiveCell.Row).Select
Selection.Copy
Sheets("Database").Select
ActiveCell.End(xlDown).Offset(1, 0).Select
ActiveSheet.Paste
End If
Next cl
End Sub
I'd do something simple like this. This may not be as efficient as some other methods, but it should do what you want it to. Also the range won't be hard coded and will change as the number of rows of data changes.
Your current code is constantly referring to
ActiveCell
(which, after the first iteration [if it ever got that far], is a cell on the "Database" sheet!), not to the cells in range A8:A23 of Sheet2.Refactored code could be: