Cells not copied in multiple loop sub

elsacerda

New Member
Joined
May 2, 2012
Messages
2
Hi,

I am trying to loop to check email addresses in column 1 of sheet4 against those of sheet2 in col 6. If found I need to copy corresponding info from sheet2 to sheet4 and then I am done with that email address from sheet4 and need to attempt the next one from sheet4. If not found continue looping in sheet2 until done with that list then loop through sheet3 col 4 looking for address, same thing if found copy info from sheet 3 and continue with next email address in sheet4, else continue looping through sheet3. So basically each address in sheet4 should be found in either sheet2 or sheet3.

The message at the end is just for debugging purposes and not needed.
I would appreciate any help. Thank you in advance. :confused:


Sub CompareRecord()
Dim Sht2LastRow As Long
Dim Sht3LastRow As Long
Dim Sht4LastRow As Long
Dim i As Long
Dim j As Long
Dim k As Long

Sht2LastRow = Sheets("Up to 2007").Cells(65536, 1).End(xlUp).Row
Sht3LastRow = Sheets("2009-2011").Cells(65536, 1).End(xlUp).Row
Sht4LastRow = Sheets("WorkFile").Cells(65536, 1).End(xlUp).Row

For i = 2 To Sht4LastRow
For j = 2 To Sht2LastRow
If Sheets("WorkFile").Cells(j, 1).Value = Sheets("Up to 2007").Cells(i, 6).Value Then
Sheets("WorkFile").Cells(j, 4).Value = Sheets("Up to 2007").Cells(i, 4).Value
Sheets("WorkFile").Cells(j, 5).Value = Sheets("Up to 2007").Cells(i, 5).Value
Sheets("WorkFile").Cells(j, 6).Value = Sheets("WorkFile").Cells(i, 1).Value
Sheets("WorkFile").Cells(j, 9).Value = Sheets("Up to 2007").Cells(i, 8).Value
GoTo Done
End If
Next j
For k = 2 To Sht3LastRow
If Sheets("WorkFile").Cells(j, 1).Value = Sheets("2009-2011").Cells(i, 4).Value Then
Sheets("WorkFile").Cells(j, 4).Value = Sheets("2009-2011").Cells(i, 2).Value
Sheets("WorkFile").Cells(j, 5).Value = Sheets("2009-2011").Cells(i, 3).Value
Sheets("WorkFile").Cells(j, 6).Value = Sheets("WorkFile").Cells(i, 1).Value
Sheets("WorkFile").Cells(j, 8).Value = Sheets("2009-2011").Cells(i, 9).Value
Sheets("WorkFile").Cells(j, 9).Value = Sheets("2009-2011").Cells(i, 10).Value
Sheets("WorkFile").Cells(j, 10).Value = Sheets("2009-2011").Cells(i, 21).Value
Sheets("WorkFile").Cells(j, 11).Value = Sheets("2009-2011").Cells(i, 1).Value
Sheets("WorkFile").Cells(j, 12).Value = Sheets("2009-2011").Cells(i, 33).Value
GoTo Done
End If
Next k
Next i
Done: MsgBox "looping"
End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,215,425
Messages
6,124,826
Members
449,190
Latest member
rscraig11

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