If autofilter has results copy, if no results insert text VBA

pook_666

Board Regular
Joined
Aug 16, 2018
Messages
94
Hi wizards,

I have the below code that copies an autofilter to a different sheet.

VBA Code:
 Sheets("Data").Range("A1").AutoFilter _
    Field:=11, Criteria1:="=Overdue"
    
    Sheets("Data").AutoFilter.Range.Copy Sheets("Debtors").Range("B17")

What I want to do is that if the autofilter produces no results, I want to put text in Sheets("Debtors").Range("B17") instead...something like Sheets("Debtors").Range("B17").value = "Nothing overdue" and if there is a result to this autofilter, then copy and paste as per above code.

I was thinking of an "IF isempty else" type of code but I don't think it's correct and cannot get this way to work....I know I am probably missing something simple with this, but any help would be great!!
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Something like:

VBA Code:
With Sheets("Data").AutoFilter.Range
If .Columns(1).specialcells(xlcelltypevisible).count > 1 then 
   .Copy Sheets("Debtors").Range("B17")
Else
Sheets("Debtors").Range("B17").value = "Nothing overdue"
end if
end with
 
Upvote 0
Solution

Forum statistics

Threads
1,215,046
Messages
6,122,854
Members
449,096
Latest member
Erald

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