how do I write a macro to replace certain cells in a colum depending on other cell va
Hello,
I am very new to spreadsheets...
I was wondering if anyone can help me with writing a macro
that would replace cell values in a column based a values in certain cells in that column.
//i would like to replace the values of cells that have the value 0 in them with the value of a variable.
<pseudocode>
Sub ChangeAll()
dim intValueOfCell
Range("A1").Select
intValueOfCell= ActiveCell.Value
Do While ActiveCell.Value <> "" 'cell is empty
If ActiveCell.Value = 0 Then
ActiveCell.Value = intValueOfCell
Else
intValueOfCell = ActiveCell.Value
End If
'select next cell in column (don't know what is the code for that
' maybe ****************
Selection.Offset(0,1).Select
'**********************
Loop
Range("A1").Select
End Sub
</pseudocode>
example of a column
***column 1***
12
0
0
0
17
0
0
89
0
0
0
0
102
0
0
160
etc...
************
I would do this manualy but there are over 8000 records (cells)
with values in them
Please help
bsw
Re: how do I write a macro to replace certain cells in a colum depending on other cell va
Quote:
Originally posted by bsw2112
I am very new to spreadsheets...
//i would like to replace the values of cells that have the value 0 in them with the value of a variable.
I would use a cell function =IF(C2<>0,C2,$A$1) where A1 is the value that replaces 0's and the colum you use for maths etc is calculated fromt eh typed info column next to it.
Never use VBa when the function is built in to the package already. Otherwise a search and replace would do the trick.
BTW: IMHO: Sounds like this speadsheet is in dire need of conversion to Access.