macro modification help

danushka

Well-known Member
Joined
Sep 6, 2009
Messages
693
Dear friends.below macro work fine for me..i need some modification on row highlighting part..this macro compere first sheet column "D" with second sheet column "D" .if any cell is matched then first sheet that matched cell row highlighting.but i need to highlight that second sheet matched cell row also......pls help me......

Code:
Sub MatchData()

  Dim Cell As Range
  Dim FoundIt As Range
  Dim LastCol As Long
  Dim LastRow As Long
  Dim Rng1 As Range
  Dim Rng2 As Range
  Dim Wks1 As Worksheet
  Dim Wks2 As Worksheet
  
    Set Wks1 = Worksheets("pending orders")
    Set Wks2 = Worksheets("prr")
    
    Set Rng1 = Wks1.Range("D8")
    Set Rng2 = Wks2.Range("D9")
    
      LastRow = Wks1.Cells(Rows.Count, Rng1.Column).End(xlUp).Row
    
      If LastRow < Rng1.Row Then Exit Sub
      Set Rng1 = Rng1.Resize(LastRow - Rng1.Row + 1, 1)
  
      LastRow = Wks2.Cells(Rows.Count, Rng2.Column).End(xlUp).Row
    
      If LastRow < Rng2.Row Then Exit Sub
      Set Rng2 = Rng2.Resize(LastRow - Rng2.Row + 1, 1)
        
        Wks1.Cells(7, "P").EntireColumn.Insert
        Wks1.Range("P7").Value = Fix(Now())
        Wks1.Range("P7").NumberFormat = "dd-mm-yy"
        LastCol = Wks1.Cells(7, Columns.Count).End(xlToLeft).Column
        
        For Each Cell In Rng1
          Set FoundIt = Rng2.Find(Cell, , xlValues, xlWhole, xlByRows, xlNext, False, False)
          If Not FoundIt Is Nothing Then
             Cell.Offset(0, 12).NumberFormat = FoundIt.Offset(0, 2).NumberFormat
             Cell.Offset(0, 12).Value = FoundIt.Offset(0, 2).Value
             Cell.Offset(0, -3).Resize(1, LastCol).Interior.ColorIndex = 6
          End If
        Next Cell
        
End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
I think that Andrew meant

Rich (BB code):
Sub MatchData()

  Dim Cell As Range
  Dim FoundIt As Range
  Dim LastCol As Long
  Dim LastRow As Long
  Dim Rng1 As Range
  Dim Rng2 As Range
  Dim Wks1 As Worksheet
  Dim Wks2 As Worksheet
  
    Set Wks1 = Worksheets("pending orders")
    Set Wks2 = Worksheets("prr")
    
    Set Rng1 = Wks1.Range("D8")
    Set Rng2 = Wks2.Range("D9")
    
      LastRow = Wks1.Cells(Rows.Count, Rng1.Column).End(xlUp).Row
    
      If LastRow < Rng1.Row Then Exit Sub
      Set Rng1 = Rng1.Resize(LastRow - Rng1.Row + 1, 1)
  
      LastRow = Wks2.Cells(Rows.Count, Rng2.Column).End(xlUp).Row
    
      If LastRow < Rng2.Row Then Exit Sub
      Set Rng2 = Rng2.Resize(LastRow - Rng2.Row + 1, 1)
        
        Wks1.Cells(7, "P").EntireColumn.Insert
        Wks1.Range("P7").Value = Fix(Now())
        Wks1.Range("P7").NumberFormat = "dd-mm-yy"
        LastCol = Wks1.Cells(7, Columns.Count).End(xlToLeft).Column
        
        For Each Cell In Rng1
          Set FoundIt = Rng2.Find(Cell, , xlValues, xlWhole, xlByRows, xlNext, False, False)
          If Not FoundIt Is Nothing Then
            FoundIt.Interior.ColorIndex = 6
             Cell.Offset(0, 12).NumberFormat = FoundIt.Offset(0, 2).NumberFormat
             Cell.Offset(0, 12).Value = FoundIt.Offset(0, 2).Value
             Cell.Offset(0, -3).Resize(1, LastCol).Interior.ColorIndex = 6
          End If
        Next Cell
        
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,845
Members
452,948
Latest member
UsmanAli786

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