I am very new to VBA and I am struggling with comparing two columns and adding missing values from H&I to J&K, while keeping the rest of my macro intact.
So far I have a macro which checks if J&K are empty, and if they are empty it adds values from H&I to them, see below:
Sub Total()
Application.ScreenUpdating = False
Dim c As Range
For Each c In Range("J23:J32" & Cells(Rows.Count, "J").End(xlUp).Row)
If c.Value = "" Then c.Value = c.Offset(, -2).Value
Next
For Each c In Range("K23:K32" & Cells(Rows.Count, "K").End(xlUp).Row)
If c.Value = "" Then c.Value = c.Offset(, -2).Value
Next
Application.ScreenUpdating = True
End Sub
I want to add two additional conditions:
- If J is not blank, then compare all of the values from H with values from J and add missing values to J to the end of the list, wherever it might be, and put values from I from to K.
So, for example, if H30 value is missing from column J, I want H30 and I30 to be added to J&K column.
- If J is not blank, then compare all of the values from H with values from J, and if the values match, then SUM the value from column I with value from column K.
For example, if H30 is present anywhere in column J, I want to sum I30 with K30.
Unfortunately this is way above my skill level, so I am humbly asking for assistance. At this point I am unsure if it's possible at all without completely changing existing logic.
Thank you very much in advance!!
Cheers