intersection

Tatu

New Member
Joined
Jun 18, 2020
Messages
6
Como posso encontrar dados na folha2 e fazer corresponder na folha1, encontrando a intersecção e preenchendo as células com cor
 

Attachments

  • sheet1.PNG
    sheet1.PNG
    187.6 KB · Views: 20
  • sheet2.PNG
    sheet2.PNG
    198.3 KB · Views: 22

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Tente a seguinte macro:

VBA Code:
Sub intersection_Dates()
  Dim sh1 As Worksheet, sh2 As Worksheet, rng As Range
  Dim a As Variant, b As Variant, c As Variant, dic1 As Object, dic2 As Object
  Dim i As Long, j As Long, k As Long, nRow As Long
  
  Set sh1 = Sheets("Folha1")
  Set sh2 = Sheets("Folha2")
  Set dic1 = CreateObject("Scripting.Dictionary")
  Set dic2 = CreateObject("Scripting.Dictionary")
  Set rng = sh1.Range("A1")
  
  sh1.Range("D4", sh1.Cells(Rows.Count, Columns.Count)).Interior.Color = xlNone
  a = sh1.Range("A4", sh1.Range("A" & Rows.Count).End(3)).Value2
  b = sh1.Range("D3", sh1.Cells(3, Columns.Count).End(1)).Value2
  c = sh2.Range("A4", sh2.Cells(sh2.Range("A" & Rows.Count).End(3).Row, _
                      sh2.Cells(3, Columns.Count).End(1).Column)).Value2
  
  For i = 1 To UBound(a, 1)
    dic1(a(i, 1)) = i + 3   'rows
  Next
  For i = 1 To UBound(b, 2)
    dic2(b(1, i)) = i + 3   'columns
  Next
  
  For i = 1 To UBound(c, 1)
    If dic1.exists(c(i, 1)) Then
      nRow = dic1(c(i, 1))
      For j = 4 To UBound(c, 2) Step 2
        If c(i, j) = "" Then Exit For
        For k = c(i, j) To c(i, j + 1)
          If dic2.exists(k) Then Set rng = Union(rng, sh1.Cells(nRow, dic2(k)))
        Next k
      Next j
    End If
  Next i
  
  rng.Interior.Color = vbYellow
  sh1.Range("A1").Interior.Color = xlNone
End Sub
 
Upvote 0
Fico feliz em ajudá-lo, obrigado por comentar.
 
Upvote 0

Forum statistics

Threads
1,212,933
Messages
6,110,751
Members
448,295
Latest member
Uzair Tahir Khan

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