Selection.End(xlUp).Select with Filtered Rows and Blank Cells then Filldown

Jambi46n2

Active Member
Joined
May 24, 2016
Messages
260
Office Version
  1. 365
Platform
  1. 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:

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:

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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