Diagonal Border Conditional Format

Q

QTGlennM

I need to apply Diagonal Borders to cells B15:B25 in an X
configuration. Based off of the values in C15:C25. If C15:C25 are
Blank no borders, If they are not blank Borders...lol. I have no idea
what I am doing and any help would be greatly appreciated!!!

God Bless
Glenn
 
G

Gary Keramidas

something like this may work for you, watch for line wrap

Sub Macro1()
Dim ws As Worksheet
Dim i As Long
Set ws = Worksheets("Sheet1")

For i = 15 To 25
With ws.Range("C" & i)
If .Value = "" Then
With .Offset(0, -1).Borders(xlDiagonalDown)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Offset(0, -1).Borders(xlDiagonalUp)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
.Offset(0, -1).Borders(xlEdgeLeft).LineStyle = xlNone
.Offset(0, -1).Borders(xlEdgeTop).LineStyle = xlNone
.Offset(0, -1).Borders(xlEdgeBottom).LineStyle = xlNone
.Offset(0, -1).Borders(xlEdgeRight).LineStyle = xlNone
Else
.Offset(0, -1).Borders(xlEdgeLeft).LineStyle = xlNone
.Offset(0, -1).Borders(xlEdgeTop).LineStyle = xlNone
.Offset(0, -1).Borders(xlEdgeBottom).LineStyle = xlNone
.Offset(0, -1).Borders(xlEdgeRight).LineStyle = xlNone
With .Offset(0, -1).Borders(xlDiagonalDown)
.LineStyle = xlNone
End With
With .Offset(0, -1).Borders(xlDiagonalUp)
.LineStyle = xlNone
End With

End If
End With
Next

End Sub
 
Q

QTGlennM

something like this may work for you, watch for line wrap

Sub Macro1()
Dim ws As Worksheet
Dim i As Long
Set ws = Worksheets("Sheet1")

For i = 15 To 25
With ws.Range("C" & i)
If .Value = "" Then
With .Offset(0, -1).Borders(xlDiagonalDown)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Offset(0, -1).Borders(xlDiagonalUp)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
.Offset(0, -1).Borders(xlEdgeLeft).LineStyle = xlNone
.Offset(0, -1).Borders(xlEdgeTop).LineStyle = xlNone
.Offset(0, -1).Borders(xlEdgeBottom).LineStyle = xlNone
.Offset(0, -1).Borders(xlEdgeRight).LineStyle = xlNone
Else
.Offset(0, -1).Borders(xlEdgeLeft).LineStyle = xlNone
.Offset(0, -1).Borders(xlEdgeTop).LineStyle = xlNone
.Offset(0, -1).Borders(xlEdgeBottom).LineStyle = xlNone
.Offset(0, -1).Borders(xlEdgeRight).LineStyle = xlNone
With .Offset(0, -1).Borders(xlDiagonalDown)
.LineStyle = xlNone
End With
With .Offset(0, -1).Borders(xlDiagonalUp)
.LineStyle = xlNone
End With

End If
End With
Next

End Sub

Worked Great is there anyway I can run it when I select the sheet?
 
G

Gary Keramidas

yes, in the vb editor, under microsoft excel objects, double click the correct
sheet and paste this in the sheet module. don't forget to change the sheet
references in the code. i refer to sheet1 here:

Private Sub Worksheet_Activate()
Dim ws As Worksheet
Dim i As Long
Set ws = Worksheets("Sheet1")

For i = 15 To 25
With ws.Range("C" & i)
If .Value = "" Then
With .Offset(0, -1).Borders(xlDiagonalDown)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Offset(0, -1).Borders(xlDiagonalUp)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
.Offset(0, -1).Borders(xlEdgeLeft).LineStyle = xlNone
.Offset(0, -1).Borders(xlEdgeTop).LineStyle = xlNone
.Offset(0, -1).Borders(xlEdgeBottom).LineStyle = xlNone
.Offset(0, -1).Borders(xlEdgeRight).LineStyle = xlNone
Else
.Offset(0, -1).Borders(xlEdgeLeft).LineStyle = xlNone
.Offset(0, -1).Borders(xlEdgeTop).LineStyle = xlNone
.Offset(0, -1).Borders(xlEdgeBottom).LineStyle = xlNone
.Offset(0, -1).Borders(xlEdgeRight).LineStyle = xlNone
With .Offset(0, -1).Borders(xlDiagonalDown)
.LineStyle = xlNone
End With
With .Offset(0, -1).Borders(xlDiagonalUp)
.LineStyle = xlNone
End With

End If
End With
Next

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top