["VBA"] comparing 8 arrays against 1

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
644
Office Version
  1. 2010
Platform
  1. Windows
Hi, I am comparing 8 arrays against one, but in order to get some results, the code I have, I need to block many line and live only one unblock, Please any help here.
this is the code:
VBA Code:
Sub com_eight()


  Dim a As Variant, b As Variant
  Dim r As Range, i As Range, j As Range, k As Long
  
  Application.ScreenUpdating = False
  
 ' Set r = Sheets("Sheet1").Range("H2:L" & Sheets("Sheet1").Range("H:L").Find("*", , xlValues, , 1, 2).Row)
  'Set r = Sheets("Sheet1").Range("N2:R" & Sheets("Sheet1").Range("N:R").Find("*", , xlValues, , 1, 2).Row)
 ' Set r = Sheets("Sheet1").Range("T2:X" & Sheets("Sheet1").Range("T:X").Find("*", , xlValues, , 1, 2).Row)
 'Set r = Sheets("Sheet1").Range("Z2:AD" & Sheets("Sheet1").Range("Z:AD").Find("*", , xlValues, , 1, 2).Row)
 'Set r = Sheets("Sheet1").Range("AF2:AJ" & Sheets("Sheet1").Range("AF:AJ").Find("*", , xlValues, , 1, 2).Row)
 'Set r = Sheets("Sheet1").Range("AL2:AP" & Sheets("Sheet1").Range("AL:AP").Find("*", , xlValues, , 1, 2).Row)
 'Set r = Sheets("Sheet1").Range("AR2:AV" & Sheets("Sheet1").Range("AR:AV").Find("*", , xlValues, , 1, 2).Row)
 Set r = Sheets("Sheet1").Range("AX2:BB" & Sheets("Sheet1").Range("AX:BB").Find("*", , xlValues, , 1, 2).Row)
 
  r.Interior.ColorIndex = 0
  For Each i In r.Rows
    k = 0
    For Each j In i.Columns
    
    
      If j.Value = Sheets("Sheet1").Range("B" & j.Row).Offset(, k).Value Then j.Interior.ColorIndex = 6
      k = k + 1
    Next
  Next
  
  Application.ScreenUpdating = True
End Sub
as you see I have seven lines block, and work like this is a little, you know, so, how is possible make it work,
thanks.
 

Some videos you may like

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,618
Office Version
  1. 2007
Platform
  1. Windows
Try this:

VBA Code:
Sub com_eight()
  Dim r As Range, i As Range, j As Range
  Dim lr As Long, k As Long
  
  Application.ScreenUpdating = False
  
  With Sheets("Sheet1")
    lr = .Range("A:BB").Find("*", , xlValues, , 1, 2).Row
    Set r = Intersect(.Range("H2:BB" & lr), .Range("H:L, N:R, T:X, Z:AD, AF:AJ, AL:AP, AR:AV, AX:BB"))
    r.Interior.ColorIndex = 0
    For Each i In r.Rows
      k = 2
      For Each j In i.Columns
        If j.Value = .Cells(j.Row, k).Value Then j.Interior.ColorIndex = 6
        k = k + 1
        If k = 7 Then k = 2
      Next
    Next
  End With
  
  Application.ScreenUpdating = True
End Sub
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,618
Office Version
  1. 2007
Platform
  1. Windows
I'm glad to help you. Thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,334
Messages
5,624,081
Members
416,010
Latest member
NJT

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
Top