ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to edit a formula. (https://www.excelbanter.com/excel-programming/331850-macro-edit-formula.html)

jimwood

Macro to edit a formula.
 
I have an old lotus macro that I would like to reproduce in excel.
Specifically I would like to have a macro open a cell in an edit mode and
have the cell be a formula of =round(/1.08,2) with the cursor sitting
just in front of the division sign so that someone could enter a number and
have it divide by 1.08. I and a coworker have been trying all sorts of
things but none of them are working.
--
Thanks,
Jim

Dave Peterson[_5_]

Macro to edit a formula.
 
This seemed to work ok for me:

Option Explicit
Sub testme01()

Dim myRng As Range
Dim myCell As Range

Set myRng = Selection

For Each myCell In myRng.Cells
With myCell
If .HasFormula Then
.Formula = "=round((" & Mid(.Formula, 2) & ")/1.08,2)"
Else
.Formula = "=round(" & .Value & "/1.08,2)"
End If
End With
Next myCell
End Sub


Select your range and test it out. It does all the cells that are selected.

jimwood wrote:

I have an old lotus macro that I would like to reproduce in excel.
Specifically I would like to have a macro open a cell in an edit mode and
have the cell be a formula of =round(/1.08,2) with the cursor sitting
just in front of the division sign so that someone could enter a number and
have it divide by 1.08. I and a coworker have been trying all sorts of
things but none of them are working.
--
Thanks,
Jim


--

Dave Peterson


All times are GMT +1. The time now is 09:37 AM.

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