If not count of range not working.

RockandGrohl

Well-known Member
Joined
Aug 1, 2018
Messages
790
Office Version
  1. 365
Platform
  1. Windows
VBA Code:
Range("A2:X" & LastrowBD).AutoFilter Field:=8, Criteria1:=">=" & PrevMon, Criteria2:="<" & PrevMon + 8
Range("A2:X" & LastrowBD).AutoFilter Field:=6, Criteria1:="Donk"
If Not Range("A2:X" & LastrowBD).SpecialCells(xlCellTypeVisible).Count > 1 Then
On Error Resume Next
ActiveSheet.ShowAllData
On Error GoTo 0
Else
    Range("J3:J" & LastrowBD).SpecialCells(xlCellTypeVisible).Copy temp.Range("G2")
    Range("M3:M" & LastrowBD).SpecialCells(xlCellTypeVisible).Copy temp.Range("H2")
    Range("N3:N" & LastrowBD).SpecialCells(xlCellTypeVisible).Copy temp.Range("I2")
End If

Hi all,

Have the above code that is working fine when results from the two filters are found, however, if the filter supplies no results, I would want it to go showalldata and then move to the next part of code.

The way my book is structured has the data from A2:X6563 or so.

LastrowBD is properly defined further up the code and correctly counts the rows.

When I apply the PrevMon (03/May/2021) filter it works correctly, and then when I apply the Donk filter, nothing is found as expected because we don't sell products under the made up name "Donk"


So yeah, I'm expecting the code to move to the clear filter part, and not the "else" part.

I've confirmed there's no excess data. When I apply the filter, we have the top row in row 1, the headers in row 2 and blank cells in visible row 3 and beyond.

I've also manually double-deleted the entire row of everything under the dataset and it's still not working.

Any ideas? I get the feeling it's crushingly simple as I have this sort of logic on multiple sheets but this is the only one giving me trouble. Thanks!
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Ah. In classic fashion, I've solved it myself mere seconds after posting.

I am counting range A2:X & lastrow, which naturally counts all the header cells too. This is why if I did .count > 23, it worked, but anything less didn't, because I have 24 header cells.

Changing to ("A2:A" & LastrowBD) worked.

I AM A TURNIP.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,799
Messages
6,126,975
Members
449,351
Latest member
Sylvine

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