Need help altering this VBA code to highlight additional data?

Coyotex3

Active Member
Joined
Dec 12, 2021
Messages
496
Office Version
  1. 365
Platform
  1. Windows
Hello guys so I obtained this VBA code which helps me highlight Matching Values on Columns C & D. And I would like to expand it a bit.

VBA Code:
Sub MatchiNV()
  Dim c As Range, r As Range, f As Range, n As Long, cell As String
  Columns("C:D").NumberFormat = "General"
  n = 2
  Set r = Range("C2", Range("C" & Rows.Count).End(3))
  r.Interior.ColorIndex = xlNone
  For Each c In Range("D2", Range("D" & Rows.Count).End(3))
    If c.Value > 0 Then
      Set f = r.Find(c, , xlValues, xlWhole)
      If Not f Is Nothing Then
        cell = f.Address
        Do
          If f.Interior.ColorIndex = xlNone Then
            f.Interior.ColorIndex = n
            c.Interior.ColorIndex = n
            n = n + 1
            If n = 56 Then n = 7
            Exit Do
          End If
          Set f = r.FindNext(f)
        Loop While Not f Is Nothing And f.Address <> cell
      End If
    End If
  Next
End Sub

The macro helps me go from this:
Book1
ABCD
1DateCodeTotalOutstanding
21/1/2023T0150.56500.25
31/1/2023T0230.3258.43
41/1/2023T0358.4330.32
51/2/2023T0433.15289.65
61/2/2023T0410.1243.27
71/2/2023T0515.63300
81/2/2023T01289.6550.56
91/3/2023T06500.25600.5
101/3/2023T04647.515.63
Source


To this:
Book1
ABCD
1DateCodeTotalOutstanding
21/1/2023T0150.56500.25
31/1/2023T0230.3258.43
41/1/2023T0358.4330.32
51/2/2023T0433.15289.65
61/2/2023T0410.1243.27
71/2/2023T0515.63300
81/2/2023T01289.6550.56
91/3/2023T06500.25600.5
101/3/2023T04647.515.63
Source


Ideally, I would like for the macro to be able to recognize that rows 5 and 6 occurred on the same "Date" and also have the same "Code" and the sum of the values on Column C(33.15 & 10.12) add up to 43.27 which is a value on Column D. So I would like for the final result to look something like this:


Book1
ABCD
1DateCodeTotalOutstanding
21/1/2023T0150.56500.25
31/1/2023T0230.3258.43
41/1/2023T0358.4330.32
51/2/2023T0433.15289.65
61/2/2023T0410.1243.27
71/2/2023T0515.63300
81/2/2023T01289.6550.56
91/3/2023T06500.25600.5
101/3/2023T04647.515.63
Source



Bonus question: Is there a way of getting this Macro to not use White as one of the interior fill colors? Cells C9 & D2 have matching values and are filled with white. I would like to avoid that if possible.

Thank you.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi,
To answer to your easiest question (avoid white as interior color) just change n=2 to n=3

Regarding the "reconciliation question" it is a huge topic on its own ...o_O
 
Upvote 0
Hi,
To answer to your easiest question (avoid white as interior color) just change n=2 to n=3

Regarding the "reconciliation question" it is a huge topic on its own ...o_O
Thank you James, that took care of it!

Yes, reconciliations are a pain, I've thought of a few different ways, but it pretty much requires me to rerun the macro again.
 
Upvote 0

Forum statistics

Threads
1,215,148
Messages
6,123,306
Members
449,095
Latest member
Chestertim

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