Autofilter

pook_666

Board Regular
Joined
Aug 16, 2018
Messages
94
<code>Hi gang - I need some help.....I'm doing an autofilter and want I want is that if the filter doesn't come up with any results, then I want to unfilter. If it does come up with a result, I want to copy the data in column H onto a different sheet.

What currently happens with my below code is that if there is no data when I filter, it ignores my unfilter command and goes straight onto adding "Equipment & Fixtures" and copies the filter header in H1 to sheet "Balance Sheet".

Any ideas?

<code>
HTML:
Sheets("Data").Columns("C:C").AutoFilter Field:=3, Criteria1:="602"

If Sheets("Data").AutoFilter.Range.Rows.Count < 1 ThenSheets("Data").Columns("C:C").AutoFilter Field:=3
Else

Sheets("Balance Sheet").Cells(Rows.Count, 4).End(xlUp).Offset(1, 0).Value = "Equipment & Fixtures"
lrow = Sheets("Data").Range("H" & Rows.Count).End(xlUp).Row
Sheets("Data").Range("H2:H" & lrow).SpecialCells(xlCellTypeVisible).Copy Sheets("Balance Sheet").Cells(Rows.Count, 5).End(xlUp).Offset(1, 0)

End If
</code></code>
 
Last edited:

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Untested, but try replacing this:
Code:
If Sheets("Data").AutoFilter.Range.Rows.Count < 1 Then

with:
Code:
If Sheets("Data").AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Cells.Count = 1 Then
 
Last edited:
Upvote 0
You're welcome, glad to help, & thanks for the feedback.:)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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