2 Columns:
Col 1 is a dropdown:
Choices: Red / Green / Yellow
Col 2: Blank
I need the code to output:
If Col1 is Green, Format Col2 as RED(filled)
if Col1 = Red or Yellow: input “n/a” in Col2.
Thanks
![]() |
Patch reliability is unclear, but widespread attacks make patching prudent. Go ahead and patch, but watch out for potential problems. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » If then Statement (Excel 2003)
Right-click the sheet tab and select View Code from the popup menu.
Create the following code in the module that is opened:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim oCell As Range
If Not Intersect(Range(“A:A”), Target) Is Nothing Then
For Each oCell In Intersect(Range(“A:A”), Target)
Select Case oCell
Case “”
oCell.Offset(0, 1).Interior.ColorIndex = xlColorIndexNone
oCell.Offset(0, 1) = “”
Case “Green”
oCell.Offset(0, 1).Interior.Color = vbRed
oCell.Offset(0, 1) = “”
Case Else
oCell.Offset(0, 1).Interior.ColorIndex = xlColorIndexNone
oCell.Offset(0, 1) = “N/A”
End Select
Next oCell
End If
End Sub
This assumes that the columns you mention are A and B. If they are different, modify the code accordingly.
That worked… Awesome:
Another dilema:
When I open it, my Macro Security is set to High so it is Disabled. No problem, I selected Medium, where it asks me to “trust” it.
How can I make this a “trusted” script to avoid the security issues? If I email this to 100 people, I will have to have them change the Security and I want to AVOID this…
Thanks
You could sign the VBA code with a digital certificate. Each user will be asked once to trust the certificate. After that, the code will run even if macro security is set to High, without asking for macros to be enabled.
However, digital certificates aren’t cheap. You’ll have to decide for yourself whether you (or your employer) can afford to get one.
See About macro security – Excel for more info.
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.
Notifications