Forum Discussion
BrianP475
May 21, 2025Copper Contributor
Move up to next blank row after copy/paste from previous sheet.
Snowman got me rolling with code that does almost exactly what Im trying to do. After I hit end of day button Im trying to get the copied data to move up to the next blank cell in column B within a ...
NikolinoDE
May 22, 2025Platinum Contributor
I don't see any inserted file, but here is an approach to your plan...I hope I understood it correctly.
If not...insert the file 🙂.
Sub CopyMarkedDataToNextBlankRows()
Dim wsSrc As Worksheet, wsDst As Worksheet
Dim rangesToCheck As Variant
Dim srcRng As Range, cell As Range
Dim destRangeStart As Long, destRangeEnd As Long
Dim destCell As Range, dataToCopy As Collection
Dim i As Long
Set wsSrc = ThisWorkbook.Sheets("Sheet1") ' Source Sheet
Set wsDst = ThisWorkbook.Sheets("Sheet2") ' Destination Sheet
' Define your source ranges (must match destination logic)
rangesToCheck = Array("2:9", "11:21", "23:29")
For i = 0 To UBound(rangesToCheck)
Set dataToCopy = New Collection
' Set source range (Column A and B)
Set srcRng = wsSrc.Range("A" & rangesToCheck(i).Split(":")(0) & ":A" & rangesToCheck(i).Split(":")(1))
' Collect values from column B where A has "t"
For Each cell In srcRng
If LCase(Trim(cell.Value)) = "t" Then
dataToCopy.Add wsSrc.Cells(cell.Row, "B").Value
End If
Next cell
' Define target range in destination sheet
destRangeStart = CLng(rangesToCheck(i).Split(":")(0))
destRangeEnd = CLng(rangesToCheck(i).Split(":")(1))
' Paste values into next available blank cells in that destination range
For Each cell In wsDst.Range("B" & destRangeStart & ":B" & destRangeEnd)
If cell.Value = "" And dataToCopy.Count > 0 Then
cell.Value = dataToCopy(1)
dataToCopy.Remove 1
End If
Next cell
Next i
MsgBox "Data transferred successfully!"
End SubMy answers are voluntary and without guarantee!
Hope this will help you.