Macro to change text color

Raza1

New Member
Joined
May 23, 2018
Messages
7
Hi Guys,

My first post :)

I have written a macro to put certain text if conditions are met but now I want the text to color red when the text is either "Please enter Account." or "Please enter Dept/Restaurant." Below is the macro I have written however this is not working. Gives me the error message "400". Any help is really appreciated. Thank you

Sub Check()


For Each Cell In Range("E9:E22")
If Cell.Value <> "" Then

If (Cell.Offset(0, -1).Value = "") And (Cell.Offset(0, -2).Value = "") Then

Cell.Offset(0, -1).Value = "Please enter Account."
Cell.Offset(0, -2).Value = "Please enter Dept/Restaurant."

ElseIf (Cell.Offset(0, -1).Value = "") Then
Cell.Offset(0, -1).Value = "Please enter Account."

ElseIf (Cell.Offset(0, -2).Value = "") Then
Cell.Offset(0, -2).Value = "Please enter Dept/Restaurant."

End If
End If

Next

For Each Cell In Range("E9:E22")
If Cell.Value <> "" Then

If (Cell.Offset(0, -1).Value = "Please enter Account.") And (Cell.Offset(0, -2).Value = "Please enter Dept/Restaurant.") Then

Cell.Offset(0, -1).Font.ColorIndex = 3
Cell.Offset(0, -2).Font.ColorIndex = 3

End If
End If

Next

MsgBox "Validated. Please check & enter missing data"


End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Gives me the error message "400".

When you run the code and get the above message, click on Debug and tell us what line of code is highlighted.
 
Upvote 0
Suggest you open the VBE, Click on the Debug item and compile the code. Then tell us if there is a compile issue. Without knowing which line is a problem, cannot offer any help. Also, what is the entire error message.

Also, look at this link

https://forums.techguy.org/threads/solved-vba-error-400-running-an-excel-macro.775340/

Thank you for that. It doesn't highlight any line in the code when I debug however the error message is : Run-time error '1004: Application-defined or object-define error.
 
Upvote 0
I took your code and entered data into column E and ran the code. It ran without error for me. I suspect that your workbook may be corrupted or maybe you have an issue with your computer.

Run a google search on "Excel Error Message 400" The good news is that it is not a coding error but something else.
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,120
Members
451,399
Latest member
alchavar

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