excel - VBA For loop with If loop -


i have issue vba code. try compare 2 columns, both , b columns. if data match, example let's a2 contains text in b3, need compare cell c2 column d. don't understand why error "end if without block if". lot guys.

here code :

sub compare() = 1 100    j = 1 50      if instr(1, activesheet.cells(i, 1).value, activesheet.cells(j, 2).value, vbtextcompare) <> 0 _      k = 1 20         if instr(1, activesheet.cells(i, 3).value, activesheet.cells(k, 4).value, vbtextcompare) <> 0 msgbox         end if      next k      end if    next j next  end sub   

i found structure of if statements bit confusing , i'm not entirely sure can loop one-liner rid of end ifs. it's worth, think code bit easier follow:

sub compare() = 1 100    j = 1 50      if instr(1, activesheet.cells(i, 1).value, activesheet.cells(j, 2).value, vbtextcompare) <> 0         k = 1 20             if instr(1, activesheet.cells(i, 3).value, activesheet.cells(k, 4).value, vbtextcompare) <> 0 msgbox         next k     end if    next j next  end sub 

this runs w/o compile error, can't comment if want do.


Comments