"x" v.b.a. code entry question

V

Vato Loco

I am currently using this code ti click "x" in to a column of cells. I
there a way I can select only certain cells in a column, like b2:b8, o
individual cells?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Target.Column <> 2 And Target.Column <> 4 Then Exit Sub

On Error GoTo errhandler
Application.EnableEvents = False
With Target.Offset(0, 1)
If .Value = "" Then
.Value = "X"
Else
.Value = ""
End If
End With

errhandler:
Application.EnableEvents = True
End Sub

Thanks, Vat
 
F

Frank Kabel

Hi
use something like
if intersect(target,me.range("B2:B8")) is nothing then exit sub
 
S

Soo Cheon Jheong

Hi,

Solution(1)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

On Error GoTo e:
Application.EnableEvents = False

If Target.Cells.Count > 1 Then GoTo e:
If Target.Row < 2 Or Target.Row > 8 Then GoTo e: 'B2:B8
If Target.Column <> 2 Then GoTo e: 'B2:B8

With Target.Offset(0, 1)
If .Value = "" Then .Value = "X" Else .ClearContents
End With

e:
Application.EnableEvents = True
End Sub
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Solution(2)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

On Error GoTo e:
Application.EnableEvents = False

If Target.Cells.Count > 1 Then GoTo e:
If Intersect(Target, Range("B2:B8")) Is Nothing Then GoTo e:

With Target.Offset(0, 1)
If .Value = "" Then .Value = "X" Else .ClearContents
End With

e:
Application.EnableEvents = True
End Sub
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



--
Regards,
Soo Cheon Jheong
_ _
^¢¯^
--
 

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