vba - Comparing cells within separate areas in Excel -


detailed explanation of requirements:

if imagine excel worksheet, assume data contained within 2 separate "groups" on worksheet.

lets first 'group1' defined data in following cells:

                             [d4, e4, f4,                               d5, e5, f5,                               d6, e6, f6] 

the second "group", 'group2', defined set of cells containing data:

                             [h4, i4, j4,                               h5, i5, j5,                               h6, i6, j6] 

i want loop through selected areas , perform comparisons follows;

                             compare d4 h4,                              compare e4 i4,                              compare f4 j4,                              compare d5 h5,                              compare e5 i5,                              compare .....                              compare f6 j6                              end 

when compare made on each iteration, if cell elements equal want background color of cell white, if cell elements unequal want background color of cell left unchanged

any advice appreciated.

see code here:

private sub commandbutton1_click()  dim rangetouse range, cell1 range, cell2 range, integer,  j integer  set rangetouse = selection  if selection.areas.count <= 1    msgbox "please select more 1 area cell cell comparsion." else     rangetouse.interior.colorindex = 39      = 1 rangetouse.areas.count       j = rangetouse.areas.count           if cell1.cells(i, j).value = cell2.cells(i, j).value                   cell1.interior.colorindex = 0                   cell2.interior.colorindex = 0           end if   next j next  end if  end sub 

ok, here @ (see code below):

from running debugger have ascertained problem need eradicate exists between line 20 , line 29.

with original code kindly provided sancho.s (see above) comparing cell in 'area1' cells in 'area2', not enough since loop progressed through 'area2' find multiple comparisons , change colorindex in multiple cells, not want this.

i want compare values in corresponding cells (assuming square selection).

to counteract included 'exit for' on line 25 leads reverse of original problem 'cell2' on line 28 not increment.

basically need way 'cell2' map location/position of 'cell1' enable like comparsion

1.)private sub commandbutton1_click() 2.) 3.)dim rangetouse range, cell1 range, cell2 range, integer,  4.)j integer 5.)dim area1 range, area2 range 6.)dim n integer 7.) 8.)set rangetouse = selection 9.)n = rangetouse.areas.count 10.) 11.)if (n <= 1) 12.)    msgbox "please select more 1 area cell  13.)            cell comparison." 14.) else 15.)    rangetouse.interior.colorindex = 39 16.)for = 1 n 17.)        set area1 = rangetouse.areas(i) 18.)        j = (i + 1) n 19.)           set area2 = rangetouse.areas(j) 20.)            each cell1 in area1.cells 21.)                each cell2 in area2.cells 22.)                    if (cell1.value = cell2.value) 23.)                        cell1.interior.colorindex = 0 24.)                        cell2.interior.colorindex = 0 25.)                        exit 26.)                    end if 27.)                     28.)                next cell2 29.)            next cell1 30.)        next j 31.)    next 32.)end if  33.)end sub 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -