VBA Vlookup with dynamic data

mdb91

New Member
Joined
Mar 6, 2018
Messages
1
I have only been using VBA for a few months and I feel like I have enough of a grasp on it to do most things but I am having issues with making my current project work.

Up to this point I have filtered my data to show only the rows I need to update the data for and cleared what used to be there. The problem I am having is that I need to update the first cell in column Y after the filter has been applied.

Example of what I normally would do.

If row 13 is the first row after the filer has been applied:
- In cell Y13 I would type "=VLOOKUP(D13,Sheet1!$D:$E,2,FALSE)"
- Then I would fill down the column

Below is the code I have been trying:

Code:
    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$AK$" & LastRow2).AutoFilter Field:=1, Criteria1:="tam"
    Columns("Y:Y").Select
    Selection.ClearContents
    Range("Y1").Select
    ActiveCell.FormulaR1C1 = "in_b"
       
    With Worksheets("Sheet2").AutoFilter.Range
        Range("D" & .Offset(1, 0).SpecialCells(xlCellTypeVisible)(1).Row).Select
    End With
    
    RowOff = ActiveCell.Row


    Range("Y" & RowOff) = Application.WorksheetFunction.VLookup(Sheets("Sheet2").Range("D" & RowOff), Sheets("Sheet1").Range("$D:$E"), 2, False)

Any guidance would be appreciated!
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,213,494
Messages
6,113,981
Members
448,538
Latest member
alex78

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