Increment text/number in a cell

C

CAWaugh

Problem: I need to select a cell that has either text or a number in it
remember this value, then with each subsequent cell selection, th
initially selected value is incremented in each new cell selected. Th
cells are scattered but most of the time they are either in one row o
column with varied row/column separations. I would like to hit a ho
spot to initiate the macro, then start making the selections. If
could enter an increment value would greatly enhance the process
 
W

whisperer

Place the following code into the Worksheet Code page. Format the sheet
as Text. Place a few numbers on the sheet and when you are ready to
start just click on any one of your numbers. When you have had enough
of that sequence, clicking on A1 will restart the sequence. Do not
place a value in A1 or that value will be the start of every sequence
from thereon.

Code:
--------------------

Option Explicit
Public Started As Boolean
Public CellValue As Integer

Sub ResetValue()
Started = False
CellValue = 0
Sheets("Sheet1").Range("A1").Select
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error GoTo xit
If ActiveCell.Column = 1 And ActiveCell.Row = 1 And CellValue > 0 Then Call ResetValue
If Started And Target <> "" Then
Exit Sub
ElseIf Not Started And (Target = "" Or Target = 0) Then
Exit Sub
End If
If Not Started Then
CellValue = Target
Else
CellValue = CellValue + 1
Target = CellValue
End If
Started = True
xit:
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