Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command button to increment a cell by 0.1 1

Status
Not open for further replies.

doogal

Computer
Jun 30, 2005
1
DE
how do I
increment Cell by .01
ie
start
k2=k2+.01
end
 
Replies continue below

Recommended for you

If the cell position is fixed use the Range object:

Range("K2").Value = Range("K2").Value + 0.01

If you want to access the cell position in code, use the Cells object:

Cells(2, 11).Value = Cells(2, 11).Value + 0.01

Good Luck
johnwm
________________________________________________________
To get the best from these forums read faq731-376 before posting

UK steam enthusiasts:
 
if you just want click around on the sheet and add to where ever you are

Sub add_to_it()
ActiveCell.Value = ActiveCell.Value + 0.1
End Sub

 
place the following code (an event procedure) in the code pane for the worksheet where you want to increment

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
With Target
.Value = .Value + 0.01
End With
Cancel = True
End Sub

double clicking any cell will increment it by 0.01

You can refine the event procedure by exiting quickly if the target cell is not one of interest. For example suppose only cells A1:A10 should be incremented then use the following

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, Range("A1:A10")) Is Nothing Then Exit Sub
With Target
.Value = .Value + 0.01
End With
Cancel = True
End Sub
 
Just to add that you should check if the value is a number before adding, as you may get an exception if you try to add to a string.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
With Target
If IsNumeric(.Value) then .Value = .Value + 0.01
End With
Cancel = True
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top