Modify cell format in VBA using WorksheetChange problem

totalnatal

New Member
Joined
Jun 9, 2010
Messages
33
Hello,

I have the following lines of code which occur if a certain cell in the worksheet equals a certain value . However, the problem is if that cell in question does not equal that value then the changes done before when the lines were run have not been taken out and remain. Is there anyway to do something like . If Cell(X:X) = Criteria Then Change those cells format, Else keep original formatting. Thanks!

Code:
If Worksheets("Settings").Cells(4, 2).Value = "Outperformance Note" Then
With Worksheets("Settings").Range("a8:b13").Borders(xlDiagonalDown)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
With Worksheets("Settings").Range("a8:b14").Borders(xlDiagonalUp)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic

End With
End With

End If
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Maybe try something like this...

Code:
    With Worksheets("Settings")
        If .Cells(4, 2).Value = "Outperformance Note" Then
            With .Range("A8:B13").Borders(xlDiagonalDown)
                .LineStyle = xlContinuous
                .Weight = xlThin
                .ColorIndex = xlAutomatic
            End With
            With .Range("A8:B14").Borders(xlDiagonalUp)
                .LineStyle = xlContinuous
                .Weight = xlThin
                .ColorIndex = xlAutomatic
            End With
[COLOR="Red"]        Else
            .Range("A8:B13").Borders(xlDiagonalDown).LineStyle = xlNone
            .Range("A8:B14").Borders(xlDiagonalUp).LineStyle = xlNone[/COLOR]
        End If
    End With
 
Upvote 0

Forum statistics

Threads
1,224,534
Messages
6,179,390
Members
452,909
Latest member
VickiS

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