How to check if the next visible cell has anything in it

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have some code that filters rows and if there is nothing found by the filter, it skips to the next sheet. How do I make this line of code
VBA Code:
 If ws.[A3].Cells.Offset(1, 0) = "" Then
refer to the next filtered, visible row as at the moment, it looks at the next row, filtered or not?



VBA Code:
        For Each ws In Worksheets
                If ws.Name <> "Cancellations" And ws.Name <> "Totals" And ws.Name <> "Sheet2" Then
                        With ws.[A3].CurrentRegion
                                .AutoFilter 1, Dt           ' autofilter for the value in cell [B27]
                                .AutoFilter 3, Req          ' autofilter for the value in cell [B25]
                                    'Check to see if the date cell, column A, for a job has anything in it. If it doesn't, turn the autofilter off and skip to the next sheet.
                                    If ws.[A3].Cells.Offset(1, 0) = "" Then
                                        .AutoFilter
                                       
                                        GoTo SkipSheet
                                    End If

I get a type mismatch with this
VBA Code:
If ws.[A3].Cells.Offset(1, 0).SpecialCells(xlCellTypeVisible) = "" Then
 
Last edited:

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
I don't quite follow but shouldn't it be....
Rich (BB code):
If ws.[A3].Offset(1, 0) <> "" Then
 
Upvote 0
If the autofilter, filters out all the results, the next visible row below row 3 (header row) will be empty so skip to the next sheet I was thinking.
 
Upvote 0
Try:

VBA Code:
                                    'Check to see if the date cell, column A, for a job has anything in it. If it doesn't, turn the autofilter off and skip to the next sheet.
                                    If .Columns(1).SpecialCells(xlCellTypeVisible).Cells.Count = 1 Then
                                        .AutoFilter
                                       
                                        GoTo SkipSheet
                                    End If
 
Upvote 0
That gives me an overflow error of this line

VBA Code:
AutoFilterCounter = .Columns(1).SpecialCells(xlCellTypeVisible).Count

in this code

VBA Code:
Sub Transfer()
        Dim ws As Worksheet, sh As Worksheet, sht As Worksheet, AutoFilterCounter As Long
        Set sh = Sheets("Totals")
        Set sht = Sheets("Cancellations")
        Dim Req As String: Req = sh.[B25].Value
        Dim Dt As String: Dt = sh.[B27].Value
        
Call TurnOffFunctionality
        
        For Each ws In Worksheets
                If ws.Name <> "Cancellations" And ws.Name <> "Totals" And ws.Name <> "Sheet2" Then
                        With ws.[A3].CurrentRegion
                                .AutoFilter 1, Dt           ' autofilter for the value in cell [B27]
                                .AutoFilter 3, Req          ' autofilter for the value in cell [B25]
                                    'Check to see if the date cell, column A, for a job has anything in it. If it doesn't, turn the autofilter off and skip to the next sheet.
                                    If ws.Columns(1).SpecialCells(xlCellTypeVisible).Cells.Count = 1 Then
                                        .AutoFilter
                                        GoTo SkipSheet
                                    End If
                                    
                                'Autofilter counter = number of visible rows
                                AutoFilterCounter = .Columns(1).SpecialCells(xlCellTypeVisible).Count
                                    'If value less than 2, only the heading is visible so skip to the next sheet.
                                    If AutoFilterCounter < 2 Then
                                        .AutoFilter
                                        GoTo SkipSheet
                                    End If
                                
                                .Offset(1).EntireRow.Copy sht.Range("A" & Rows.Count).End(xlUp).Offset(1)
                                .Offset(1).EntireRow.Delete
                                .AutoFilter                 ' turn off the autofilter
                        End With
                End If
SkipSheet:
        Next ws
        
'sh.Range("B25,B27").ClearContents
Call TurnOnFunctionality

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

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