decadence
Well-known Member
- Joined
- Oct 9, 2015
- Messages
- 525
- Office Version
- 365
- 2016
- 2013
- 2010
- 2007
- Platform
- Windows
Hi, I am currently using a Vlookup but the problem is the static columns and my columns will change from time to time.
I would like to base the search criteria on an Array of Headers and step through the Array of Headers if Found in Row 1 or Row 2, if not then do nothing.
Then I would like to be able to Match 2 columns and return the value of the adjacent cell if found and if not then skip to the next cell rather N/A or 0 being returned.
Hope this makes sense. Thanks
From This
[TABLE="width: 500"]
<tbody>[TR]
[TD]Header1[/TD]
[TD]Header2[/TD]
[TD]Header3[/TD]
[TD]Header4[/TD]
[TD][/TD]
[TD][/TD]
[TD]Header5[/TD]
[TD]Header6[/TD]
[TD]Header7[/TD]
[TD]Header8[/TD]
[/TR]
[TR]
[TD]A1[/TD]
[TD]1.1[/TD]
[TD]1.1[/TD]
[TD]0[/TD]
[TD][/TD]
[TD][/TD]
[TD]A1[/TD]
[TD]10.1[/TD]
[TD]5.222[/TD]
[TD]180[/TD]
[/TR]
[TR]
[TD]B2[/TD]
[TD]1.2[/TD]
[TD]1.2[/TD]
[TD]0[/TD]
[TD][/TD]
[TD][/TD]
[TD]B2[/TD]
[TD]3.4[/TD]
[TD]5.4[/TD]
[TD]180[/TD]
[/TR]
[TR]
[TD]C3[/TD]
[TD]1.3[/TD]
[TD]1.3[/TD]
[TD]0[/TD]
[TD][/TD]
[TD][/TD]
[TD]D4[/TD]
[TD]7.6[/TD]
[TD]9.8[/TD]
[TD]270[/TD]
[/TR]
[TR]
[TD]D4[/TD]
[TD]1.4[/TD]
[TD]1.4[/TD]
[TD]0[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
To This
[TABLE="width: 500"]
<tbody>[TR]
[TD]Header1[/TD]
[TD]Header2[/TD]
[TD]Header3[/TD]
[TD]Header4[/TD]
[TD][/TD]
[TD][/TD]
[TD]Header5[/TD]
[TD]Header6[/TD]
[TD]Header7[/TD]
[TD]Header8[/TD]
[/TR]
[TR]
[TD]A1[/TD]
[TD]10.1[/TD]
[TD]5.222[/TD]
[TD]180[/TD]
[TD][/TD]
[TD][/TD]
[TD]A1[/TD]
[TD]10.1[/TD]
[TD]5.222[/TD]
[TD]180[/TD]
[/TR]
[TR]
[TD]B2[/TD]
[TD]3.4[/TD]
[TD]5.4[/TD]
[TD]180[/TD]
[TD][/TD]
[TD][/TD]
[TD]B2[/TD]
[TD]3.4[/TD]
[TD]5.4[/TD]
[TD]180[/TD]
[/TR]
[TR]
[TD]C3[/TD]
[TD]1.3[/TD]
[TD]1.3[/TD]
[TD]0[/TD]
[TD][/TD]
[TD][/TD]
[TD]D4[/TD]
[TD]7.6[/TD]
[TD]9.8[/TD]
[TD]270[/TD]
[/TR]
[TR]
[TD]D4[/TD]
[TD]7.6[/TD]
[TD]9.8[/TD]
[TD]270[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Code:
Sub Update()
Dim LastRow As Long
LastRow = Range("A" & Rows.Count).End(xlUp).row
Application.ScreenUpdating = False
Range("I2:I" & LastRow).FormulaR1C1 = "=VLOOKUP(C[-8],C[4]:C[7],2,FALSE)"
Range("J2:J" & LastRow).FormulaR1C1 = "=VLOOKUP(C[-9],C[3]:C[6],3,FALSE)"
Range("K2:K" & LastRow).FormulaR1C1 = "=VLOOKUP(C[-10],C[2]:C[5],4,FALSE)"
Columns("I:K").Copy: Columns("I:K").PasteSpecial xlPasteValues
Cells.Replace What:="#N/A", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows
[m1].Resize(, 4).EntireColumn.Delete
Application.ScreenUpdating = True
End Sub
I would like to base the search criteria on an Array of Headers and step through the Array of Headers if Found in Row 1 or Row 2, if not then do nothing.
Then I would like to be able to Match 2 columns and return the value of the adjacent cell if found and if not then skip to the next cell rather N/A or 0 being returned.
Hope this makes sense. Thanks
From This
[TABLE="width: 500"]
<tbody>[TR]
[TD]Header1[/TD]
[TD]Header2[/TD]
[TD]Header3[/TD]
[TD]Header4[/TD]
[TD][/TD]
[TD][/TD]
[TD]Header5[/TD]
[TD]Header6[/TD]
[TD]Header7[/TD]
[TD]Header8[/TD]
[/TR]
[TR]
[TD]A1[/TD]
[TD]1.1[/TD]
[TD]1.1[/TD]
[TD]0[/TD]
[TD][/TD]
[TD][/TD]
[TD]A1[/TD]
[TD]10.1[/TD]
[TD]5.222[/TD]
[TD]180[/TD]
[/TR]
[TR]
[TD]B2[/TD]
[TD]1.2[/TD]
[TD]1.2[/TD]
[TD]0[/TD]
[TD][/TD]
[TD][/TD]
[TD]B2[/TD]
[TD]3.4[/TD]
[TD]5.4[/TD]
[TD]180[/TD]
[/TR]
[TR]
[TD]C3[/TD]
[TD]1.3[/TD]
[TD]1.3[/TD]
[TD]0[/TD]
[TD][/TD]
[TD][/TD]
[TD]D4[/TD]
[TD]7.6[/TD]
[TD]9.8[/TD]
[TD]270[/TD]
[/TR]
[TR]
[TD]D4[/TD]
[TD]1.4[/TD]
[TD]1.4[/TD]
[TD]0[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
To This
[TABLE="width: 500"]
<tbody>[TR]
[TD]Header1[/TD]
[TD]Header2[/TD]
[TD]Header3[/TD]
[TD]Header4[/TD]
[TD][/TD]
[TD][/TD]
[TD]Header5[/TD]
[TD]Header6[/TD]
[TD]Header7[/TD]
[TD]Header8[/TD]
[/TR]
[TR]
[TD]A1[/TD]
[TD]10.1[/TD]
[TD]5.222[/TD]
[TD]180[/TD]
[TD][/TD]
[TD][/TD]
[TD]A1[/TD]
[TD]10.1[/TD]
[TD]5.222[/TD]
[TD]180[/TD]
[/TR]
[TR]
[TD]B2[/TD]
[TD]3.4[/TD]
[TD]5.4[/TD]
[TD]180[/TD]
[TD][/TD]
[TD][/TD]
[TD]B2[/TD]
[TD]3.4[/TD]
[TD]5.4[/TD]
[TD]180[/TD]
[/TR]
[TR]
[TD]C3[/TD]
[TD]1.3[/TD]
[TD]1.3[/TD]
[TD]0[/TD]
[TD][/TD]
[TD][/TD]
[TD]D4[/TD]
[TD]7.6[/TD]
[TD]9.8[/TD]
[TD]270[/TD]
[/TR]
[TR]
[TD]D4[/TD]
[TD]7.6[/TD]
[TD]9.8[/TD]
[TD]270[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Last edited: