Put an X on a Cell

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.
 
F

Frank Kabel

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
 
F

Frank Kabel

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.
 
D

Dave Peterson

Maybe it was the first line that wrapped:

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

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