clear if blank

Trevor3007

Well-known Member
Joined
Jan 26, 2017
Messages
667
Office Version
  1. 365
Platform
  1. Windows
hi & hope this finds you well?

I am using the following VBA, but although it inserts the applicable colour, if you then make that cel blank, the colour remains. Can soem kind person pleas insert the applciable for me?

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)


Application.ScreenUpdating = False
    Dim rng As Range
      
    For Each rng In Range("e9:e39:b200")
        Select Case rng.Value
            Case "Off"
                With Range("A" & rng.Row).Resize(1, 7)
                    .Interior.ColorIndex = 36
                    .Font.Bold = True
                End With
               
            Case "off"
                With Range("A" & rng.Row).Resize(1, 7)
                    .Interior.ColorIndex = 36
                    .Font.Bold = True
                End With
        End Select
    Next rng
   
      
    Application.ScreenUpdating = True


If Target.Cells.Count > 1 Or Target.HasFormula Then Exit Sub



    On Error Resume Next

    If Not Intersect(Target, Range("jb6:jb18")) Is Nothing Then

        Application.EnableEvents = False

        Target = UCase(Target)

        Application.EnableEvents = True

    End If
     

    On Error GoTo 0


If Target.Cells.Count > 1 Or Target.HasFormula Then Exit Sub



    On Error Resume Next

    If Not Intersect(Target, Range("e6:e40")) Is Nothing Then

        Application.EnableEvents = False

        Target = StrConv(Target, vbProperCase)

        Application.EnableEvents = True

    End If

    On Error GoTo 0

     
   
 
End Sub

Many thanks in advance,
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
How about
VBA Code:
    For Each rng In Range("B9:E200")
        If LCase(rng.Value) = "off" Then
            With Range("A" & rng.Row).Resize(1, 7)
                .Interior.ColorIndex = 36
                .Font.Bold = True
            End With
         ElseIf rng.Value = "" Then
            With Range("A" & rng.Row).Resize(1, 7)
                .Interior.ColorIndex = xlNone
                .Font.Bold = False
            End With
        End If
    Next rng
 
Upvote 0
Solution
How about
VBA Code:
    For Each rng In Range("B9:E200")
        If LCase(rng.Value) = "off" Then
            With Range("A" & rng.Row).Resize(1, 7)
                .Interior.ColorIndex = 36
                .Font.Bold = True
            End With
         ElseIf rng.Value = "" Then
            With Range("A" & rng.Row).Resize(1, 7)
                .Interior.ColorIndex = xlNone
                .Font.Bold = False
            End With
        End If
    Next rng
hi fluff,

sir, you are a genius... thank you :}
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,934
Members
449,094
Latest member
teemeren

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