Match cell value in list then then add new values to end of row

tanke

New Member
Joined
Aug 30, 2016
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Hello all

I'm sure the following scenario is entry level stuff but it's still beyond my meagre VBA abilities!

I have a list of names and wish to add data (dates) to the end of the row alongside each name (depending on the name)

Capture.PNG


i.e press the button, search for John then update the row so that the result is

Capture2.PNG


any help is much appreciated!
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
I built this code in general way. The two table could have name that does not exits in each other.
May be:
VBA Code:
Option Explicit
Sub test()
Dim lr&, lc&, i&, j&, k&, t&, c&, rng1, rng2, arr(1 To 10000, 1 To 1000)
lr = Cells(Rows.Count, "B").End(xlUp).Row
rng1 = Range("B2:C" & lr).Value2
lr = Cells(Rows.Count, "F").End(xlUp).Row
lc = Range("F18").CurrentRegion.Columns.Count + 5
rng2 = Range("F18", Cells(lr, lc)).Value2
For i = 1 To UBound(rng1)
    k = k + 1
    arr(k, 1) = rng1(i, 1): arr(k, 2) = rng1(i, 2)
    For j = 1 To UBound(rng2)
        If rng1(i, 1) = rng2(j, 1) Then
            For t = 2 To UBound(rng2, 2)
                arr(k, t + 1) = rng2(j, t)
            Next
        End If
    Next
Next
For i = 1 To UBound(rng2)
    c = 0
    For j = 1 To UBound(rng1)
        If rng2(i, 1) = rng1(j, 1) Then c = c + 1
    Next
    If c = 0 Then
        k = k + 1
        arr(k, 1) = rng2(i, 1)
        For t = 2 To UBound(rng2, 2)
            arr(k, t + 1) = rng2(i, t)
        Next
    End If
Next
Range("B2").CurrentRegion.ClearContents
Range("B2").Resize(k, UBound(rng2, 2) + 1).Value = arr
End Sub

before.JPG
after.JPG
 
Upvote 0
thanks for your reply, I'll give it a go later on today!
 
Upvote 0

Forum statistics

Threads
1,215,731
Messages
6,126,532
Members
449,316
Latest member
sravya

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