I need any row in Sheet1 that has the word 'Done' in column E to be cut and pasted into the next empty row of Sheet2. My problem is that I don't know how to find the next empty row in Sheet2 and start pasting values to that next empty row.
It's a basic Workbook with two Sheets. Sheet1 has all employee tasks and Sheet2 only displays the tasks that are 'Done'. Anytime an employee finishes a task and types 'Done' in a cell within Column E of Sheet1, that entire row needs to be cut and pasted into the next empty row of Sheet2. I created an ActiveX Command button in Sheet1 with the following code. The code finds any cell in Sheet1 that says 'Done' and cuts/pastes it in Sheet2, but it always starts pasting from the beginning of Sheet2, and I need it to start pasting from the next empty row of Sheet2.
Private Sub CommandButton1_Click()
Dim c As Range
Dim j As Integer
Dim Source As Worksheet
Dim Target As Worksheet
' Change worksheet designations as needed
Set Source = ActiveWorkbook.Worksheets("Sheet1")
Set Target = ActiveWorkbook.Worksheets("Sheet2")
j = 1 ' Start copying to row 1 in target sheet
For Each c In Source.Range("E1:E1000") ' Do 1000 rows
If c = "Done" Then
Source.Rows(c.Row).Cut Target.Rows(j)
j = j + 1
End If
Next c
End Sub
My problem is that it keeps overwriting anything that's already in Sheet2 because I don't know what to replace that 'j' variable code with. I need it to find the next empty row in Sheet2 and start pasting from there.
Workhseet_Change
event to trigger the cut/paste automatically. Lookup how to find last used row in Excel vba. You'll get plenty of results that can help. – Scott HoltzmanRange.End
,Range.Offset
,Worksheet.UsedRange
andFor
loops are all different possibilities on how to go about this – Chronocidal