Dynamic Selection.Autofill

92Ber

New Member
Joined
Oct 5, 2017
Messages
1
Hi.


  1. 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 :)


  1. 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
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Forum statistics

Threads
1,223,911
Messages
6,175,331
Members
452,636
Latest member
laura12345

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