Two for each loops

twckfa16

New Member
Joined
Dec 17, 2012
Messages
31
Hello -

I am trying to compare one column in 2 files in filtered worksheets ...if the row is 1 go to the next row. If the values are the same go to the next row…if not keep a count. So here is a little bit of the code

VBA Code:
For Each cell1 in Range1
  For Each cell2 in Range2
    if cell1.Offest (r, 13).row = 1 then
        if cell2.offet (r, 13).row = 1 then
        Else
        End if
    else
        value1 = cell1.offset(r, 3).value
        value2 = cell2.offset(r, 3).value
        
        if value1 = value2
        'go tk next row'
        else
          count = count + 1
        end if
     end if
    
  next cell2
 
 next cell1

It seems to go through well comparing the first row ..then it goes to the next row in the first sheet Ok but then fails to go to next row in the second .

I figured it had something to do with the nested For Each ‘s because it will just keep looping between one file only.

Thanks !
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
The below should be:

value1 = cell1.offset(r, 13).value
value2 = cell2.offset(r, 13).value

Thanks !
 
Upvote 0

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

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