Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Changing the cell format doesn't change existing cell content | Excel Discussion (Misc queries) | |||
Formatting worksheets, existing and new, in existing workbooks | Excel Discussion (Misc queries) | |||
Add 10% to the existing value in a cell | Excel Discussion (Misc queries) | |||
Can I add 1 # to an existing # in a cell? | Excel Discussion (Misc queries) | |||
download existing spreadsheets into another existing spreadsheet | Excel Discussion (Misc queries) |