Macro "IF" Condition

GreatOffender

Board Regular
Joined
Feb 2, 2015
Messages
53
Greetings, With a lot of board help I was able to cobble together a functional macro to assist in my day to day work requirements. I do however have a problem that has been on and off and I will explain. The problem is "on" when the macro places a filter an condition that are not met and it halts and awaits debugging. Fortunately this has been the exception and not the rule but today I have time to work on it so I will present my dilemma and hope anyone and everyone with Macro experience will be able to lead me out of the woods. Problem occurs when none of the entries meet the filter requirements and the data changes daily so I cannot foresee the impending issue until it is run.

Thank you,



VBA Code:
Set wf = Application.WorksheetFunction
Set rngData = .Range("A2:A" & lngLastRow)
    With rngData
    .AutoFilter Field:=3, Criteria1:=Array( _
        "3456", "3125", "3451", "3110", "3370"), Operator:=xlFilterValues
    For Each c In wsd.AutoFilter.Range.Range("M2:M" & lngLastRow).SpecialCells(xlCellTypeVisible)
        c.Value = wf.WorkDay(c.Value, 1)
    Next
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
There are a few ways you can go about this.
You can count how many rows your filter returns using the SUBTOTAL function shown here: Excel formula: Count visible rows in a filtered list | Exceljet.
(note to use this in VBA, you would preface it with Application.Worksheetfunction.Subtotal(...))

Another thing you can do is add error handling to your VBA code to ignore/bypass that error.
You can check out this link, specifically the "On Error Statement" section.
 
Upvote 0
Thank you for your reply. I believe the VBA Error Handling... is not only informative but certainly more than sufficient.

Thanks again!
 
Upvote 0

Forum statistics

Threads
1,214,588
Messages
6,120,412
Members
448,960
Latest member
AKSMITH

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