VBA Compare dynamic H&I, add value from H to I if not present in I to the end of the list

Xiggie

New Member
Joined
Feb 23, 2022
Messages
12
Office Version
  1. 2013
Platform
  1. Windows
Hello!

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:

VBA Code:
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:

  1. 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.

  1. 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.

Columns A:G are irrelevant under the circumstances.

Clear macro is as follows:

VBA Code:
Sub ClearContents()
Range("J23", "K53").ClearContents
End Sub


Thank you very much in advance!!

Cheers
EyLS7.png
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,214,583
Messages
6,120,377
Members
448,955
Latest member
BatCoder

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