VBA to Match Row and Column to Value, then copy and paste into intersection

mill6210

New Member
Joined
Nov 9, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have a table with many fields, and each record in the table has a unique ID.
I want to find the intersection of a particular ID and a particular field , and then copy and paste a value into the cell where they intersect.

In the attached example, I need a macro that when run, the name and the date would be inserted into the respective columns, in the row that matches the value in F2. I am struggling with the VBA to accomplish this, I greatly appreciate any help!

Cheers.
 

Attachments

  • Screenshot 2023-11-10 000339.png
    Screenshot 2023-11-10 000339.png
    3.4 KB · Views: 34

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.
Do you just mean something like this ?

VBA Code:
Sub AddDataToTable()

    Dim ws As Worksheet
    Dim lo As ListObject
    Dim loRow As Long
    
    Set ws = ActiveSheet                        ' Ideally put in the worksheet name ie Worksheets("NameOfSheet")
    Set lo = ws.Range("Table1").ListObject      ' Change to your table name
    
    'Find record in table
    With Application
        loRow = .IfError(.Match(ws.Range("F1"), lo.ListColumns("Column1").DataBodyRange, 0), 0)
    End With
    
    'Write data
    With ws
        If loRow <> 0 Then
            lo.ListColumns(.Range("E3").Value).DataBodyRange(loRow) = .Range("F3")
            lo.ListColumns(.Range("E4").Value).DataBodyRange(loRow) = .Range("F4")
        End If
    End With
        
End Sub
 
Upvote 1
Solution

Forum statistics

Threads
1,223,886
Messages
6,175,198
Members
452,616
Latest member
intern444

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