Increment numbers in column A by 1 when selected

M

mikeburg

Need code to increment a number from the cell above in column A when
column A cell is selected. Have tried using the following code but the
number does not increment by 1, it merely copies the number from the
cell above.

(1) Why does the following code not work?

(2) What would be the modification to make the following code work or
what would be the simple code to take the number from above in column
A, add 1, & put it in the selected cell of column A if the selected
cell is blank, empty, or -0-?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
R = Target.Row
If Target.Row > 3 And Target.Column = 1 And Cells(R, 1) = 0 _
And Cells((R - 1), 1).Value > 0 Then
Cells(R, 1).Value = Cells((R - 1), 1).Value + 1
End If
End Sub

Thanks a million. mikeburg
 
A

Ardus Petus

Your code generates an error if you select A1

'----------
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With Target
If .Row > 3 And .Column = 1 Then
If .Value = 0 And .Offset(-1, 0).Value > 0 Then
.Value = .Offset(-1, 0).Value + 1
End If
End If
End With
End Sub
'-----------

"mikeburg" <[email protected]> a écrit
dans le message de
news:[email protected]...
 
A

Ardus Petus

If Target.Row > 3 And Target.Column = 1 And Cells(R, 1) = 0 _
And Cells((R - 1), 1).Value > 0 Then

Cells((R-1),1) errs if R = 1
 

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