Loop On Two Columns

VitesseCarOwner

Board Regular
Joined
Jun 29, 2012
Messages
79
I have two columns of data J2:K1000, I need loop through both columns at the same time and copy the data into cells into E1 and F2, then run through the remainder of the code. The code below I have adapted but cannot get it to work correctly. Can anyone help?



HTML:
Sub Test()
Dim LastRowColJ, LastRowColK As Long
Sheets("Sheet1").Select
LastRowColJ = Range("J65536").End(xlUp).Row
For Each c In Worksheets("Sheet1").Range("J2:J" & LastRowColJ).Cells
Sheets("Sheet1").Range("E1").Value = c
For Each d In Worksheets("Sheet1").Range("K2:K" & LastRowColJ).Cells
Sheets("Sheet1").Range("F2").Value = d
'My other code goes here!
Next
Next
End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
I think this does what you want:

Code:
Sub Test()
    Sheets("Sheet1").Range("E2:F" & Sheets("Sheet1").Range("J" & Rows.Count).End(xlUp).Row).Value = Sheets("Sheet1").Range("J2:K" & Sheets("Sheet1").Range("J" & Rows.Count).End(xlUp).Row).Value
End Sub
 
Upvote 0
Code:
Sub Test()
Dim ColJLR As Long
Dim i As Long
ColJLR = Sheets("Sheet1").Range("J" & Rows.Count).End(xlUp).Row
For i = 2 To ColJLR
    Sheets("Sheet1").Range("E" & i & ":F" & i).Value = Sheets("Sheet1").Range("J" & i & ":K" & i).Value
    
    'Add other things you wish to do within row loop
Next i
        
MsgBox "Done!"
    
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,901
Messages
6,122,157
Members
449,068
Latest member
shiz11713

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top