×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Command button to increment a cell by 0.1

Command button to increment a cell by 0.1

Command button to increment a cell by 0.1

(OP)
how do I
increment Cell by .01
ie   
start
 k2=k2+.01
end

RE: Command button to increment a cell by 0.1

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: www.essexsteam.co.uk

RE: Command button to increment a cell by 0.1

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

RE: Command button to increment a cell by 0.1

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

RE: Command button to increment a cell by 0.1

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources