Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Have a co-worker that wants to change the formulas in his spreadsheet
to add "=round(" to the front and ",0" to the end. Formulas may be long or short and there are plenty of them. He would like a simple macro so he could activate a cell, and hit the shortcut keys, and make the conversion. Thanks for any help. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
See this message I just posted (Subject: @ Round Formulas)
In article , (JDeBeer) wrote: Have a co-worker that wants to change the formulas in his spreadsheet to add "=round(" to the front and ",0" to the end. Formulas may be long or short and there are plenty of them. He would like a simple macro so he could activate a cell, and hit the shortcut keys, and make the conversion. Thanks for any help. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
JE McGimpsey just posted this in response to a similar post:
One way: Select the range of cells you want to convert. The range can include Text, constants, etc - only the formulae will be converted. Change the "0" in the cell.Formula line to the number of places you want to round to. Public Sub WrapARound() Dim cell As Range On Error Resume Next For Each cell In Selection.SpecialCells(xlCellTypeFormulas) cell.Formula = "=ROUND(" & Mid(cell.Formula, 2) & ",0)" Next cell On Error GoTo 0 End Sub You might add: xlNumbers in the Special Cells and also, if he is only going to do one cell, then I added some code for that as well Public Sub Wrap_A_Round() Dim cell As Range, rng as Range On Error Resume Next if Selection.Count = 1 then if selection.HasFormula then set rng = cell else set rng = Nothing end if else set rng = Selection.SpecialCells(xlCellTypeFormulas,xlNumber s) End if if not rng is nothing then For Each cell In rng cell.Formula = "=ROUND(" & Mid(cell.Formula, 2) & ",0)" Next cell End if On Error GoTo 0 End Sub -- Regards, Tom Ogilvy "JDeBeer" wrote in message om... Have a co-worker that wants to change the formulas in his spreadsheet to add "=round(" to the front and ",0" to the end. Formulas may be long or short and there are plenty of them. He would like a simple macro so he could activate a cell, and hit the shortcut keys, and make the conversion. Thanks for any help. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
or to use David McRitchie's technique (makes the code more compact and fewer
instructions) Public Sub Wrap_A_Round() Dim cell As Range, rng as Range On Error Resume Next set rng = Intersect(Selection.Selection.SpecialCells(xlCellT ypeFormulas,xlNumbers)) if not rng is nothing then For Each cell In rng cell.Formula = "=ROUND(" & Mid(cell.Formula, 2) & ",0)" Next cell End if On Error GoTo 0 End Sub -- Regards, Tom Ogilvy "Tom Ogilvy" wrote in message ... JE McGimpsey just posted this in response to a similar post: One way: Select the range of cells you want to convert. The range can include Text, constants, etc - only the formulae will be converted. Change the "0" in the cell.Formula line to the number of places you want to round to. Public Sub WrapARound() Dim cell As Range On Error Resume Next For Each cell In Selection.SpecialCells(xlCellTypeFormulas) cell.Formula = "=ROUND(" & Mid(cell.Formula, 2) & ",0)" Next cell On Error GoTo 0 End Sub You might add: xlNumbers in the Special Cells and also, if he is only going to do one cell, then I added some code for that as well Public Sub Wrap_A_Round() Dim cell As Range, rng as Range On Error Resume Next if Selection.Count = 1 then if selection.HasFormula then set rng = cell else set rng = Nothing end if else set rng = Selection.SpecialCells(xlCellTypeFormulas,xlNumber s) End if if not rng is nothing then For Each cell In rng cell.Formula = "=ROUND(" & Mid(cell.Formula, 2) & ",0)" Next cell End if On Error GoTo 0 End Sub -- Regards, Tom Ogilvy "JDeBeer" wrote in message om... Have a co-worker that wants to change the formulas in his spreadsheet to add "=round(" to the front and ",0" to the end. Formulas may be long or short and there are plenty of them. He would like a simple macro so he could activate a cell, and hit the shortcut keys, and make the conversion. Thanks for any help. |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() If ActiveCell.Formula < "" Then ActiveCell.Formula = "=ROUND(" _ & Right(ActiveCell.Formula, Len(ActiveCell.Formula) _ - 1) & ",0)" End If If I undestood right: 1. check cell has formula 2. attach =round( and ,0) to the cell's existing formula minus original '=' (always 1st) char. -----Original Message----- Have a co-worker that wants to change the formulas in his spreadsheet to add "=round(" to the front and ",0" to the end. Formulas may be long or short and there are plenty of them. He would like a simple macro so he could activate a cell, and hit the shortcut keys, and make the conversion. Thanks for any help. . |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
This worked in Excel97
Sub myformula() ' Keyboard Shortcut: Ctrl+q ActiveCell.Formula = "=round(" & Right(ActiveCell.Formula, Len(ActiveCell.Formula) - 1) & ",0)" End Sub watch word wrap change 'q' to your choice. -- sb "JDeBeer" wrote in message om... Have a co-worker that wants to change the formulas in his spreadsheet to add "=round(" to the front and ",0" to the end. Formulas may be long or short and there are plenty of them. He would like a simple macro so he could activate a cell, and hit the shortcut keys, and make the conversion. Thanks for any help. |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks for everyone's help.
jdb |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
changing cell formulas | Excel Discussion (Misc queries) | |||
copying formulas and changing cell references | Excel Discussion (Misc queries) | |||
changing cell background colors with formulas | Excel Worksheet Functions | |||
Changing Multiple Cell Formulas | Excel Discussion (Misc queries) | |||
Changing Cell References in Formulas | Excel Worksheet Functions |