Macro for diagonal border based on the input of a cell?

didge_player

New Member
Joined
Nov 11, 2013
Messages
4
Hello,
I am fairly new to writing macros for excel. I have played around with programming in C but that is it.
I am wanting to make a macro that reads the value in a cell (C4) and if that value >= 3 then a certain cell lets say (i31) has a diagonal up border. Else nothing.
This is the basic of what I want to do and once I have this I am sure I can modify it and expand on it for the rest of my project.
Any help and thoughts would great.
Thanks
didge_player
 

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.
Hi and welcome to the forum
Code:
Sub MM1()
If Range("C4").Value >= 3 Then
    With Range("I31").Borders(xlDiagonalUp)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
End If
End Sub
 
Upvote 0
Thanks @Michael M
Is there a way to make it run automatic or do I have to run macros everything I type in a new number in to Cell C4?
Thanks
 
Upvote 0
Copy this code into the Sheet module....NOT a standard or This workbook module
Code:
Sub worksheet_change(ByVal target As Range)
Set target = Range("C4")
Range("I31").Borders(xlDiagonalUp).LineStyle = xlNone
If target.Count > 1 Then Exit Sub
If Intersect(target, Range("C4")) Is Nothing Then Exit Sub
If target.Value >= 3 Then
    With Range("I31").Borders(xlDiagonalUp)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
End If
End Sub
 
Upvote 0
That's great. Thanks so much Michael.
The only problem I am having with it is if I protect my worksheet so that only Cell C4 can be changed it crashes the macro.
Any thoughts?
Thanks
David
 
Upvote 0
Try
Code:
Sub worksheet_change(ByVal target As Range)
ActiveSheet.Unprotect
Set target = Range("C4")
Range("I31").Borders(xlDiagonalUp).LineStyle = xlNone
If target.Count > 1 Then Exit Sub
If Intersect(target, Range("C4")) Is Nothing Then Exit Sub
If target.Value >= 3 Then
    With Range("I31").Borders(xlDiagonalUp)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
End If
ActiveSheet.Protect
End Sub
 
Upvote 0
absolutely perfect.
I have modified what you gave me and it now changes 30 or so different cells to great different patterns based on a single input number.

Thanks so much.
David
 
Upvote 0
pleasure...glad it worked for you...(y)
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,716
Members
449,093
Latest member
Mnur

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