Hi.
I am using macro to search for a cell with "Exchange", insert a column on its left and use vlookup. Everything works fine when "Exchange" is in Column G. I want to change the macro so the Selection.AutoFill autofills the Vlookup functions in the inserted Column even when the "Exchange" wasn't in Column G.
Any help will be appreciated
I know that
Code:=VLOOKUP(RC[1], {""CGH"",""CPH"",""DTB"",""EEX"",""EUX"",""HEX"",""IST"",""MIL"",""MRV"",""NPX"",""OSL"",""OTB"",""PMI"",""RTF"",""RTS"",""SEP"",""STO"",""UAX"",""WSE"",""WSF"",""WTB"",""PGS""}, 1, 0)
doesn't work. At the beginning I had
Code:=VLOOKUP(RC[1], $B$2:$B$22 from another workbook, 1, 0),
but I wanted to avoid opening the second workbook everytime I want to use that macro, so I tried to insert the list in the table_array in vlookup. Is there a way to fix it?
Code:
Sub Vlookup2()
' VlookupExchange Macro
Dim LR As Long
Rows("1:1").Select
Cells.Find(What:="Exchange", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
ActiveCell.EntireColumn.Insert
LR = Range("C" & Rows.Count).End(xlUp).Row
ActiveCell.FormulaR1C1 = "VLOOKUP_EXCHANGE"
Range("G2").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[1], {""CGH"",""CPH"",""DTB"",""EEX"",""EUX"",""HEX"",""IST"",""MIL"",""MRV"",""NPX"",""OSL"",""OTB"",""PMI"",""RTF"",""RTS"",""SEP"",""STO"",""UAX"",""WSE"",""WSF"",""WTB"",""PGS""}, 1, 0)"
Range("G2").Select
Selection.AutoFill Destination:=Range("G2:G" & LR)
ActiveCell.EntireColumn.Columns.AutoFit
ActiveCell.Offset(-1).Select
Selection.AutoFilter
End Sub