abrcrmdl23
New Member
- Joined
- Apr 16, 2021
- Messages
- 2
- Office Version
- 2016
- Platform
- Windows
Hello All,
I am new here and fairly new to VBA in general. I have been able to piece together part of what I need but I am struggling to finish the code.
In a nutshell I need the macro (Module 4 - AddtoFOPMaster) to do an index match from Sheet 1 cell C6 to Column A in Table1 in sheet Master FOP List. Then if it finds a match replace the data in the matched row found with the range data below (yes the code below will need tweaked to do this because that code adds a new row, but it has the correct data references for the table ranges)
Sub AddtoFOPMaster()
Dim ws As Worksheet
Set ws = Sheets("Master FOP List")
Dim tbl As ListObject
Set tbl = ws.ListObjects("FOP")
Dim newrow As ListRow
Set newrow = tbl.ListRows.Add
With newrow
.Range(1) = Worksheets("Sheet1").Range("C6")
.Range(2) = Worksheets("Sheet1").Range("D6")
.Range(3) = Worksheets("Sheet1").Range("C10")
.Range(4) = Worksheets("Sheet1").Range("B20")
End With
End Sub
If there is no match then I just need it to run the above code which adds a row and data to Table 1. I am struggling with the transition to do either or and I am terrible at index matching.
Any help would be much appreciated. I added a sample worksheet if you wanted to see it.
I am new here and fairly new to VBA in general. I have been able to piece together part of what I need but I am struggling to finish the code.
In a nutshell I need the macro (Module 4 - AddtoFOPMaster) to do an index match from Sheet 1 cell C6 to Column A in Table1 in sheet Master FOP List. Then if it finds a match replace the data in the matched row found with the range data below (yes the code below will need tweaked to do this because that code adds a new row, but it has the correct data references for the table ranges)
Sub AddtoFOPMaster()
Dim ws As Worksheet
Set ws = Sheets("Master FOP List")
Dim tbl As ListObject
Set tbl = ws.ListObjects("FOP")
Dim newrow As ListRow
Set newrow = tbl.ListRows.Add
With newrow
.Range(1) = Worksheets("Sheet1").Range("C6")
.Range(2) = Worksheets("Sheet1").Range("D6")
.Range(3) = Worksheets("Sheet1").Range("C10")
.Range(4) = Worksheets("Sheet1").Range("B20")
End With
End Sub
If there is no match then I just need it to run the above code which adds a row and data to Table 1. I am struggling with the transition to do either or and I am terrible at index matching.
Any help would be much appreciated. I added a sample worksheet if you wanted to see it.