VBA - IsEmpty on filtered dataset

jcooooper

Board Regular
Joined
Mar 24, 2018
Messages
52
Hi all,

I have a code that filters data, and then I have the following function:

Code:
If IsEmpty([B]Range("A14").Offset(1, 0)[/B]) = False Then


    
    'Is not blank
    MsgBox "ABC"
    
Else
    'Is blank


MsgBox "XYZ"
Essentially I'm trying to see if the next available row in the data is blank.... but the offset function looks includes the filtered data.

Is there any way to select the row below the active cell, excluding the filtered data? i.e the same that would be selected if you just press the down arrow on a filtered data set?

Many thanks!
 

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
4,915
Office Version
365
Platform
Windows
Do you want the first empty row below your data or do you want to test the next filtered row below current active cell to see if column A is blank ?

Please post the line of code which filters the data

thanks
 
Last edited:

jcooooper

Board Regular
Joined
Mar 24, 2018
Messages
52
Might be a bit hard as there are named ranges, but essentially the filter columns are row 14...


Code:
Sub Funds_futures()


If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False


Sheets("Data").Select
Range("A14").Select




Range("Data_column_headers").AutoFilter Range("data_portfolio_name").Column, Application.Transpose(Range("Mapping_cash_portfolio_codes")), xlFilterValues
Range("Data_column_headers").AutoFilter Field:=Range("data_security_group").Column, Criteria1:="<>Cash"


If IsEmpty(Range("A14").Offset(1, 0)) = False Then


    

    MsgBox "Test 1"
    
Else



MsgBox "Test 2."


If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False


End If
I'm trying to ascertain if the once the above filters are applied, if anything is left from A15 downwards

One way to do that is just press the down arrow from A14...if that's blank there's nothing left. The offset(1,0) just selects A15 (which always has a value).

Hope that makes sense
 
Last edited:

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
4,915
Office Version
365
Platform
Windows
see if this returns the correct cell for you

Code:
Sub NextCell()
   
    MsgBox Range("A15", Range("A" & Rows.Count)).SpecialCells(xlCellTypeVisible).Cells(1, 1).Address(0, 0)
   
End Sub
 

jcooooper

Board Regular
Joined
Mar 24, 2018
Messages
52
see if this returns the correct cell for you

Code:
Sub NextCell()
   
    MsgBox Range("A15", Range("A" & Rows.Count)).SpecialCells(xlCellTypeVisible).Cells(1, 1).Address(0, 0)
   
End Sub
I can't seem to get this to work, just returns a message box with the row number? Unless I'm doing it wrong. I've tried it in various places in my code
 

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
4,915
Office Version
365
Platform
Windows
Using your original code

Code:
Sub NextCell()
    If IsEmpty(Range("A15", Range("A" & Rows.Count)).SpecialCells(xlCellTypeVisible).Cells(1, 1)) = False Then
        MsgBox "ABC"
    Else
        MsgBox "XYZ"
    End If
End Sub
 

jcooooper

Board Regular
Joined
Mar 24, 2018
Messages
52
Using your original code

Code:
Sub NextCell()
    If IsEmpty(Range("A15", Range("A" & Rows.Count)).SpecialCells(xlCellTypeVisible).Cells(1, 1)) = False Then
        MsgBox "ABC"
    Else
        MsgBox "XYZ"
    End If
End Sub
Works perfect, thanks so much!
 

Forum statistics

Threads
1,085,475
Messages
5,383,906
Members
401,864
Latest member
MaryKayte

Some videos you may like

This Week's Hot Topics

Top