ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Add value to existing cell value (https://www.excelbanter.com/excel-programming/291017-add-value-existing-cell-value.html)

peter

Add value to existing cell value
 
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

Newbie

Add value to existing cell value
 
Something like
dim bal as variant
bal = ActiveSheet.Cells(1, 1).Value
bal = bal + Z
ActiveSheet.Cells(1,1).Value = bal

HTH
"Peter" wrote in message
...
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




Ron de Bruin

Add value to existing cell value
 
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


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Peter" wrote in message ...
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





All times are GMT +1. The time now is 02:52 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com