question on macro

K

kara

I am using the following macro to increase the value of a cell on a double
click how. I cannot make it work for columns c,d,e,and f. Can anyone offer
any solutions?

Private Sub Worksheet_BeforeDoubleClick(ByVal Target _
As Range, Cancel As Boolean)
If Target.Row = 1 Then Exit Sub
If Target.Column <> 2 Then Exit Sub 'Require Col B
On Error Resume Next
Application.EnableEvents = False
Target.Value = Target.Value + 1
Application.EnableEvents = True
If Err.Number <> 0 Then
MsgBox "Unable to add 1 to value in cell " _
& Target.Address(0, 0)
End If
End Sub
 
B

Bob Phillips

Change

If Target.Column <> 2 Then Exit Sub 'Require Col B

to

If Target.Column < 3 Or Target.Column > 7 Then Exit Sub

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
T

Tom Ogilvy

Private Sub Worksheet_BeforeDoubleClick(ByVal Target _
As Range, Cancel As Boolean)
If Target.Row = 1 Then Exit Sub
If Target.Column < 2 or Target.column > 6 Then Exit Sub 'Require Col B
On Error Resume Next
Application.EnableEvents = False
Target.Value = Target.Value + 1
Application.EnableEvents = True
If Err.Number <> 0 Then
MsgBox "Unable to add 1 to value in cell " _
& Target.Address(0, 0)
End If
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