Jambi46n2
Active Member
- Joined
- May 24, 2016
- Messages
- 260
- Office Version
- 365
- Platform
- Windows
Hello,
I'm having a rough time using VBA to VLOOKUP a filtered spreadsheet.
There's over 50 columns and 100's of rows. Most are hidden and filtered.
I'm trying to automate the "filldown" portion of my code.
This has proven problematic as the entire column isn't completly blank.
So this portion of the code gets stuck in a cell with data in it and wont FillDown:
Range(Selection, Selection.End(xlUp)).Select
Selection.FillDown
My question is, can there be a way where I can select the entire column minus the header and to the last active cell on the bottom to filldown my VLOOKUP formula? The first portion of the formula will be the first filtered cell/row below the header. The column letters aren't always the same so I need this to work in any column. Otherwise this would be easier.
Here's the complete code:
I appreciate any assistance you can provide.
I'm having a rough time using VBA to VLOOKUP a filtered spreadsheet.
There's over 50 columns and 100's of rows. Most are hidden and filtered.
I'm trying to automate the "filldown" portion of my code.
This has proven problematic as the entire column isn't completly blank.
So this portion of the code gets stuck in a cell with data in it and wont FillDown:
Range(Selection, Selection.End(xlUp)).Select
Selection.FillDown
My question is, can there be a way where I can select the entire column minus the header and to the last active cell on the bottom to filldown my VLOOKUP formula? The first portion of the formula will be the first filtered cell/row below the header. The column letters aren't always the same so I need this to work in any column. Otherwise this would be easier.
Here's the complete code:
Code:
[COLOR=#008000]'Use Loop to Select One Cell Down With Filter On[/COLOR]
ActiveCell.Select
ActiveCell.Offset(1, 0).Select
Do Until ActiveCell.EntireRow.Hidden = False
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Select
[COLOR=#008000] 'VLOOKUP[/COLOR]
Application.CutCopyMode = False
Dim sheetName, lookupFrom, myRange ' always declare your variables
sheetName = "final data" ' note I added some spaces to make it challenging
lookupFrom = "E:E"
myRange = "'" & sheetName & "'!A:D" ' putting quotes around the string so it's always valid
ActiveCell.Formula = "=VLOOKUP(E:E, '" & sheetName & "'!A:D, 4,0)"
ActiveCell.Select
ActiveCell.Offset(0, 1).Select
Do Until ActiveCell.EntireColumn.Hidden = False
ActiveCell.Offset(0, 1).Select
Loop
Selection.End(xlDown).Select
ActiveCell.Offset(0, -1).Select
Do Until ActiveCell.EntireColumn.Hidden = False
ActiveCell.Offset(0, -1).Select
Loop
[COLOR=#ff0000] Range(Selection, Selection.End(xlUp)).Select[/COLOR]
Selection.FillDown
I appreciate any assistance you can provide.
Last edited: