Set wscf = Sheets(Range("I2").Value) Set wsjr = Sheets("Reminders") lastRow =…
- User
Set wscf = Sheets(Range("I2").Value) Set wsjr = Sheets("Reminders")
lastRow = wscf.Cells(Rows.count, "B").End(xlUp).Row
For i = 5 To lastRow If wscf.Cells(i, "I").Value = "" Then MsgBox ("Found") Set copyRange = wscf.Range("J" & i) If Not IsEmpty(copyRange) Then wsjr.Range("D8").Offset(1, 0).Resize(copyRange.Rows.count, 1).Value = copyRange.Value MsgBox ("Print") End If End If Next i In this code the copyRange is not printing to the next row down after each loop
- Assistant
To print the copyRange to the next row down after each loop, you can update the line
wsjr.Range("D8").Offset(1, 0).Resize(copyRange.Rows.count, 1).Value = copyRange.Valueto use a variable counter to track the next available row. Here's the modified code:Set wscf = Sheets(Range("I2").Value) Set wsjr = Sheets("Reminders") lastRow = wscf.Cells(Rows.Count, "B").End(xlUp).Row Dim nextRow As Long nextRow = wsjr.Cells(Rows.Count, "D").End(xlUp).Row + 1 For i = 5 To lastRow If wscf.Cells(i, "I").Value = "" Then MsgBox ("Found") Set copyRange = wscf.Range("J" & i) If Not IsEmpty(copyRange) Then wsjr.Range("D" & nextRow).Value = copyRange.Value MsgBox ("Print") nextRow = nextRow + 1 End If End If Next iIn this modified code,
nextRowis initially set as the next available row in column D of thewsjrworksheet (wsjr.Cells(Rows.Count, "D").End(xlUp).Row + 1). After each loop, it is incremented by 1 (nextRow = nextRow + 1), which ensures that the next iteration of the loop prints thecopyRangeto the next row down.