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

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
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,215,336
Messages
6,124,331
Members
449,155
Latest member
ravioli44

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