Add value to existing cell value

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

Hello,

Appreciate if someone could tell me how to make the macro
add a value to a cell (from a variable). I.e. if there is
a number of 3 in cell A1 and the variable Z has a value of
2, this should generate a result of 5 in cell A1.

Thanks in advance!

Peter
 
Something like
dim bal as variant
bal = ActiveSheet.Cells(1, 1).Value
bal = bal + Z
ActiveSheet.Cells(1,1).Value = bal

HTH
 
For the activecell

Sub test()
Dim z As Long
z = 3
With ActiveCell
If IsNumeric(.Value) Then
.Value = .Value + z
End If
End With
End Sub

Try this for the selection

Sub test2()
Dim z As Long
Dim cell As Range
z = 3
For Each cell In Selection
If IsNumeric(cell.Value) Then
cell.Value = cell.Value + z
End If
Next
End Sub
 
Back
Top