Excel - Compare arrays and specify which columns to compare until the first column is blank -


i looking compare 2 arrays in same sheet row row, specify column in array 1 should compared column in array 2 , until value column blank. example array 1 a:e , array 2 g:l , compare column b values in column g , column compared values in column l.

what best way , how can stop when value blank row i'm comparing in column when i'm comparing columns b , g?

at moment looks need loop through each column in turn mean 5 separate loops below.

sub comparesheets(shtbefore string) dim mycell range dim mydiffs integer  each mycell in activeworkbook.worksheets(shtbefore).range("l:l")     if not mycell.value = activeworkbook.worksheets(shtbefore).range("a:a").cells(mycell.row, mycell.column).value          mydiffs = mydiffs + 1      end if next  each mycell in activeworkbook.worksheets(shtbefore).range("g:g")         if not mycell.value = activeworkbook.worksheets(shtbefore).range("b:b").cells(mycell.row, mycell.column).value          mydiffs = mydiffs + 1      end if   next  'repeated 3 more times.....  end sub 

how this:

sub comparesheets(shtbefore string) dim strarray variant dim mydiffs integer dim lnglastrow long dim mycell range  each strarray in array("l/a", "g/b")     activeworkbook.worksheets(shtbefore)         lnglastrow = .cells(.rows.count, split(strarray, "/")(0)).end(xlup).row         each mycell in .range(split(strarray, "/")(0) & "1:" & split(strarray, "/")(0) & lnglastrow)             if not mycell.value = .range(split(strarray, "/")(1) & mycell.row).value                 mydiffs = mydiffs + 1             end if         next     end next strarray  end sub 

obviously, can extend upon array include additional columns compare 1 another. l/a stands for: compare column l column a, column l (the first column) dictates how many rows compared (until there no more in column l though there still might more in column a).

note, optimize code using .value2 instead of .value if that's option.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -