runtime error 1004 in conditional formatting macro recording

valmir

Active Member
Joined
Feb 10, 2021
Messages
267
Office Version
  1. 365
Platform
  1. Windows
Hello everyone: I'm having the above error in the line below when trying to run that macro recording for conditional formatting:
ExecuteExcel4Macro "(2,1,"";;;"")"
This is the full macro recording:
VBA Code:
Sub Macro2()
'
' Macro2 Macro
'

'
    Range("A1").Select
    Selection.NumberFormat = ";;;"
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=IF(OR(NOT(ISNUMBER(INDIRECT(""'""&$D$2&""'!HQ5""))));OR(NOT(ISNUMBER(INDIRECT(""'""&$D$3&""'!HQ5"")))))"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    ExecuteExcel4Macro "(2,1,"";;;"")"
    Selection.FormatConditions(1).StopIfTrue = False
End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
The macro recorder does not cope with recording the user's choice of cell number format. The result of its powerlessness is the code just shown.
Replace
VBA Code:
ExecuteExcel4Macro "(2,1,"";;;"")"
with
VBA Code:
Selection.FormatConditions(1).NumberFormat = ";;;"

Artik
 
Upvote 0
The macro recorder does not cope with recording the user's choice of cell number format. The result of its powerlessness is the code just shown.
Replace
VBA Code:
ExecuteExcel4Macro "(2,1,"";;;"")"
with
VBA Code:
Selection.FormatConditions(1).NumberFormat = ";;;"

Artik
It worked! Thank you so much! :)👏👏👏
 
Upvote 0
The VBA code works but it changed the formula and the way it changed the formula, it doesn't work as it was supposed to. The original formula:
Excel Formula:
=IF(OR(NOT(ISNUMBER(INDIRECT("'"&$D$2&"'!HQ5"))));OR(NOT(ISNUMBER(INDIRECT("'"&$D$3&"'!HQ5")))))
was changed into this:
Excel Formula:
=IF(OR(NOT(ISNUMBER(INDIRECT(""'""&$D$2&""'!HQ5""))));OR(NOT(ISNUMBER(INDIRECT(""'""&$D$3&""'!HQ5"")))))
If I manually input the original formula, it works. If I replace the original formula into the code, it gives me run-time error 5: invalid procedure call or argument!
If I use the VBA code with the changed formula, the formula doesn't work!
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,118
Members
453,021
Latest member
Justyna P

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