Application.Run - If Any Cell in Column W has an Error

norts55

Board Regular
Joined
Jul 27, 2012
Messages
183
Is there a way to run a macro from a macro with an If Statement?

What I am trying to do is run "Macro2" if any cell in Column W on Sheet "Sheet_1" contains and error.

If this can be done I will put it at the end of an existing macro I have.

Below is a very basic macro I have. I cannot figure out how to put an if statement into the Application.Run portion.

VBA Code:
Sheets("Sheet_1").Select
Columns("W:W").Select
Selection.SpecialCells(xlCellTypeFormulas, 16).Select
Application.Run "'" & ActiveWorkbook.Name & "'" & "!Macro2"


2021-11-10_17h04_35.png
 

Attachments

  • 2021-11-10_17h04_35.png
    2021-11-10_17h04_35.png
    20.6 KB · Views: 2
  • 1636586081532.png
    1636586081532.png
    5 KB · Views: 1

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
How about this? :

VBA Code:
    Dim ErrorCount  As Long
    Dim rng         As Range
'
    Set rng = Sheets("Sheet1").Range("W1:W" & Sheets("Sheet1").Range("W" & Rows.Count).End(xlUp).Row)
'
    ErrorCount = Application.Evaluate("COUNTIF(" & rng.Address & ",IsError)")

    If ErrorCount > 0 Then
        Application.Run "'" & ActiveWorkbook.Name & "'" & "!Macro2"
    End If
 
Upvote 0
Solution
How about
VBA Code:
   Dim Rng As Range
   Sheets("Sheet_1").Select
   On Error Resume Next
   Set Rng = Columns("W:W").SpecialCells(xlFormulas, 16)
   On Error GoTo 0
   If Not Rng Is Nothing Then
      Application.Run "'" & ActiveWorkbook.Name & "'" & "!Macro2"
   End If
 
Upvote 0
I only tested johnnyL's and that gave me the results I was looking for. I am sure Fluff's works too but I haven't tested it.

Thank you both for the reply's. The knowledge from this group always amazes me.
 
Upvote 0

Forum statistics

Threads
1,214,974
Messages
6,122,536
Members
449,088
Latest member
RandomExceller01

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