VBA Question - Help!

madab

New Member
Joined
Jan 29, 2014
Messages
27
Hi - hoping something might be able to help me with this one...
What I need to do is the following: insert a number of vlookups into an excel worksheet, autofill to the last row of data, copy and paste special values to remove the formulae. The vlookups need to start after the last column of data in row 3 (i.e. the number of columns may not be fixed each time). I have been able to write a macro that will put the vlookups into each cell in each column. However I can't figure out how to autofill the vlookup's to be last row of data. I'd normally use something along the lines of: Dim x as long, x = range("A65000").End(xlup).Row, Range("????").Autofill Destination:=Range("???" & x)

Any ideas?

Thanks
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
For what it's worth, once you start using VBA to insert formulas into cells, there's a good chance you're making it all too complicated and can probably simplify how you've got it all set up.
 
Upvote 0
What's the code you have so far?
 
Upvote 0
.
.

Perhaps you can adapt something like this:

Code:
Sub InsertFunction()

    Dim lst_col As Integer
    Dim lst_row As Long
    Dim row_num As Long
    
    With Worksheets(1)
        lst_col = .Cells(2, .Columns.Count).End(xlToLeft).Column
        lst_row = .Cells(.Rows.Count, lst_col).End(xlUp).Row
    
        For row_num = 3 To lst_row
            .Cells(row_num, lst_col + 1).Formula = _
                "=VLOOKUP(" & .Cells(row_num, lst_col).Address(False, False) & "," & _
                Worksheets(2).Name & "!A:B,2,FALSE)"
        Next row_num
    End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,647
Messages
6,120,722
Members
448,987
Latest member
marion_davis

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