Put an X on a Cell

  • Thread starter Thread starter Kyle
  • Start date Start date
K

Kyle

Is there a way to put a X border lines on a cell when user
click on it. I have a month calendar setup. I want to be
able to click on day(s) on the month by put an X border
line on that day cell. Click again and it will take the X
border line off. It is just the same way as I right click
the mouse, select cell format, border then click a diagonal
lines. I like to done it in one click.

Thanks.
 
Hi
you can try the following code (put it in the worksheet module)

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel
As Boolean)

If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range("A:A")) Is Nothing Then Exit Sub

With Target
If .Borders(xlDiagonalDown).LineStyle = xlContinuous Then
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
Else
With .Borders(xlDiagonalDown)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Borders(xlDiagonalUp)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End If
End With
Cancel = True
End Sub


This will toggle the border cross for each DOUBLE click. Currently it
processes only column A. You may change the second line of the code
according to your spreadsheet layout
 
Hi
you mean the line
If Target.Cells.Count > 1 Then Exit Sub

This works fine for me. what kind of error did you receive.
 
Maybe it was the first line that wrapped:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
 
Back
Top