Hello,
I have made the below code but I can't figure out how to loop it.
What I would like the below code to do is....if value in column N in Workbooks("Data.xlsx").Sheets("Data") is bigger than 10000 then copy the cell D in than same row and paste it wsMacro.Range("A" & nr)
For me only works now if I do for one only cell.
Hope someone can help me. If unclear please let me know.
<code>
Sub Macro1()
Dim wsData As Worksheet
Dim wsMacro As Worksheet
Dim nr As Long, lr As Long
Dim c As Range
Set wsData = Workbooks("Data.xlsx").Sheets("Data")
Set wsMacro = Workbooks("Over 50k Report (testing).xlsm").Sheets("NEW Invoices")
lr = wsData.Range("D" & Rows.Count).End(xlUp).Row
nr = wsMacro.Range("A" & Rows.Count).End(xlUp).Row + 1
For Each c In wsData.Range("N246")
If c.Value > 10000 Then
'copy the row
wsData.Range("D246").Copy
'paste the row
wsMacro.Range("A" & nr).PasteSpecial xlPasteAll
'set next row number
nr = nr + 1
End If
Next c
End Sub
</code>
I have made the below code but I can't figure out how to loop it.
What I would like the below code to do is....if value in column N in Workbooks("Data.xlsx").Sheets("Data") is bigger than 10000 then copy the cell D in than same row and paste it wsMacro.Range("A" & nr)
For me only works now if I do for one only cell.
Hope someone can help me. If unclear please let me know.
<code>
Sub Macro1()
Dim wsData As Worksheet
Dim wsMacro As Worksheet
Dim nr As Long, lr As Long
Dim c As Range
Set wsData = Workbooks("Data.xlsx").Sheets("Data")
Set wsMacro = Workbooks("Over 50k Report (testing).xlsm").Sheets("NEW Invoices")
lr = wsData.Range("D" & Rows.Count).End(xlUp).Row
nr = wsMacro.Range("A" & Rows.Count).End(xlUp).Row + 1
For Each c In wsData.Range("N246")
If c.Value > 10000 Then
'copy the row
wsData.Range("D246").Copy
'paste the row
wsMacro.Range("A" & nr).PasteSpecial xlPasteAll
'set next row number
nr = nr + 1
End If
Next c
End Sub
</code>
Last edited: