I am having a really hard time copying rows from a loop to a loop. The destiniation loop is all blank cells. I have been stuck on this for 3 days now, i feel so unproductive. What am i missing?
Sub Testloop()
Dim a As Range, b As Range, d As Range
Sheets("SAP Output DATA").Select
Range(Cells(2, "A"), Cells(Rows.Count, "A").End(xlUp)).Select
Selection.SpecialCells(xlCellTypeBlanks).Offset(0, 4).Select
Set d = Selection
Sheets("Input DATA").Select
Range("B2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Set a = Selection
For Each b In a.Rows
b.Copy
For Each row In d.Rows
b.PasteSpecial
Next row
Next b
End Sub
It copies the data over, but the data it copies over is all original data from row 2, the next blank cell doesnt contain the next row data from the Input DATA sheet. How can i loop through the rows and paste them into the blank cells?
see images:
1. https://i.stack.imgur.com/Jd95G.png
2. https://i.stack.imgur.com/444RO.png
After a long day, i still cant solve it. This is as close as i think ill ever get it.
Sub Testshttestonemoretime()
Dim a As Range, b As Range, d As Range, f As Range
Dim i As Long, r As Range, coltoSearch As String
Dim sht As Worksheet
Set sht = ThisWorkbook.ActiveSheet
Sheets("Input DATA").Select
Range("B2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Set a = Selection
Sheets("SAP Output DATA").Select
For Each b In a.Rows
MsgBox b.Address
For Each Address In b
coltoSearch = "A"
For i = 2 To Range(coltoSearch & Rows.Count).End(xlUp).row
Set r = Range(coltoSearch & i)
If Len(r.Value) = 0 Then
MsgBox "No Value, in " & r.Address
b.Copy Destination:=Cells(i, 5)
End If
Next i
Next Address
Next b
End Sub
Excel Sheet to download with the problem:
https://drive.google.com/file/d/0B-ZY6BZH9zh5WGpuY0RPZk5Mb2c/view?usp=sharing
the button is called "Copy text to color" on sap data sheet
so Far the only thing i got working in a way that works, mostly. I have no idea why it fails sometimes; is this:
Sub WorkingLoop()
Dim a As Range, b As Range, d As Range, f As Range, e As Range
Dim i As Long, r As Range, coltoSearch As String
Dim sht As Worksheet
Set sht = ThisWorkbook.Worksheets("Input DATA")
Sheets("Input DATA").Select
Range("B2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Set a = Selection
Sheets("SAP Output DATA").Select
For Each b In a.Rows
'MsgBox b.Address
Set f = sht.Range(b.Address)
f.Copy
coltoSearch = "A"
For i = 2 To Range(coltoSearch & Rows.Count).End(xlUp).row
Set r = Range(coltoSearch & i)
If Len(r.Value) = 0 Then
'MsgBox "No Value, in " & r.Address
Set e = Range(r.Address)
For Each cell In e
e.PasteSpecial
Next cell
End If
Next i
e.PasteSpecial
Next b
End Sub