ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Modify an existing Cell formula using VBA (https://www.excelbanter.com/excel-discussion-misc-queries/145559-modify-existing-cell-formula-using-vba.html)

Matt[_2_]

Modify an existing Cell formula using VBA
 
If I have a formula in cell A1 that contains the following: "=C1" ...and I
want to KEEP that formula ("=C1") but also ADD to the end if it the
following: "*10" so that it becomes: "=C1*10" using VBA, is that possible?

My users need to select ranges of cells and then multiply them *10 but the
formulas can't be erased while doing this. Right now I have a simple "For
Each MyCell in Selection, MyCell = MyCell*10 but this of course overwrites
the formulas if they are present, so it only works for the cells without
formulas.

Thank You for any advise!!



Bob Phillips

Modify an existing Cell formula using VBA
 
For Each myCell In Selection
If myCell.HasFormula Then
myCell.Formula = mycell.formula & "*10"
End If
Next myCell

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Matt" wrote in message
...
If I have a formula in cell A1 that contains the following: "=C1" ...and I
want to KEEP that formula ("=C1") but also ADD to the end if it the
following: "*10" so that it becomes: "=C1*10" using VBA, is that possible?

My users need to select ranges of cells and then multiply them *10 but the
formulas can't be erased while doing this. Right now I have a simple "For
Each MyCell in Selection, MyCell = MyCell*10 but this of course overwrites
the formulas if they are present, so it only works for the cells without
formulas.

Thank You for any advise!!




Matt[_2_]

Modify an existing Cell formula using VBA
 
Hey, thank you!

"Bob Phillips" wrote in message
...
For Each myCell In Selection
If myCell.HasFormula Then
myCell.Formula = mycell.formula & "*10"
End If
Next myCell

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)

"Matt" wrote in message
...
If I have a formula in cell A1 that contains the following: "=C1" ...and
I want to KEEP that formula ("=C1") but also ADD to the end if it the
following: "*10" so that it becomes: "=C1*10" using VBA, is that
possible?

My users need to select ranges of cells and then multiply them *10 but
the formulas can't be erased while doing this. Right now I have a simple
"For Each MyCell in Selection, MyCell = MyCell*10 but this of course
overwrites the formulas if they are present, so it only works for the
cells without formulas.

Thank You for any advise!!







All times are GMT +1. The time now is 05:33 AM.

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