VBA code for Cond. Formatting

cdsaroma

Board Regular
Joined
Feb 5, 2003
Messages
200
Would someone be able to put this into VBA code?
I've tried but can't work out how to do it.

Cell ranges N2:N1000 & E2:E1000

Condition 1: =N2="m" [Cell.Font.ColorIndex = 0 Cell.Interior.ColorIndex = 10 Cell.Font.Bold = True]
Condition 2: =OR(N2="vg",N2="g") [Cell.Font.ColorIndex = 0 Cell.Interior.ColorIndex = 14 Cell.Font.Bold = True]
Condition 3: =N2="n" [Cell.Font.ColorIndex = 0 Cell.Interior.ColorIndex = 9 Cell.Font.Bold = True]
Condition 4: =IF(E2="x",N2="") [Cell.Font.ColorIndex = 0 Cell.Interior.ColorIndex = 3 Cell.Font.Bold = True]

If Cell.Value <> to any of the criteria then [Cell.Font.ColorIndex = 0 Cell.Interior.ColorIndex = 0]

thanks
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hi cdsaroma,

This code should do it:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Intersect(Target, Range("N2:N1000,E2:E1000")) Is Nothing Then Exit Sub
   With Target
      Select Case .Text
         Case "m"
            .Font.ColorIndex = 0
            .Interior.ColorIndex = 10
            .Font.Bold = True
         Case "vg", "g"
            .Font.ColorIndex = 0
            .Interior.ColorIndex = 14
            .Font.Bold = True
         Case "n"
            .Font.ColorIndex = 0
            .Interior.ColorIndex = 9
            .Font.Bold = True
         Case "x", ""
            .Font.ColorIndex = 0
            .Interior.ColorIndex = 3
            .Font.Bold = True
         Case Else
            .Font.ColorIndex = 0
            .Interior.ColorIndex = 0
      End Select
   End With
End Sub

This code must be place in the worksheet's event code module. To do this, right-click on the worksheet's tab, select View Code and paste this code into the Code pane.

Keep Excelling.

Damon
 
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,451
Members
452,915
Latest member
hannnahheileen

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