Help with 2 macros

GusC

New Member
Joined
Jul 28, 2009
Messages
2
Hi,

Wondering if anyone can help with 2 macros I have that work but both have kinks that I would like to check

1) Number format macro
................ Selection.NumberFormat = "#,##0;[Red](#,##0);-;"
This macro is for formatting numbers in a way I like. However if I inadvertantly use it on text, it will not show the text. I just need to change something small but not sure what it is - can anyone shed any light please

2) Round Formula macro
................
Sub Round_Add() <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
'// = = = = = = = = = = = = = = = = = = = = = = = = = = = <o:p></o:p>
'// Adds =ROUND( ) to Formulas in current Selection <o:p></o:p>
'// May have more than one area selected <o:p></o:p>
'// Avoids adding Round to beginning if already used <o:p></o:p>
'// = = = = = = = = = = = = = = = = = = = = = = = = = = = <o:p></o:p>
<o:p> </o:p>
Dim BigRng As Range <o:p></o:p>
Dim Rng As Range <o:p></o:p>
Dim Cell As Range <o:p></o:p>
Dim Equ As String <o:p></o:p>
Dim iRound As Integer <o:p></o:p>
<o:p> </o:p>
On Error Resume Next <o:p></o:p>
If Not (TypeOf Selection Is Range) Then Exit Sub <o:p></o:p>
Set BigRng = Selection.SpecialCells(xlFormulas) <o:p></o:p>
If BigRng Is Nothing Then Exit Sub <o:p></o:p>
<o:p> </o:p>
iRound = InputBox("Round to how many digits?", , 0) <o:p></o:p>
<o:p> </o:p>
Equ = "=Round(#,n_)" <o:p></o:p>
Equ = Replace(Equ, "n_", iRound) <o:p></o:p>
<o:p> </o:p>
For Each Rng In BigRng.Areas <o:p></o:p>
For Each Cell In Rng.Cells <o:p></o:p>
If Not Cell.Formula Like "=ROUND(*" Then <o:p></o:p>
Cell.Formula = Replace(Equ, "#", Mid$(Cell.Formula, 2)) <o:p></o:p>
End If <o:p></o:p>
Next Cell <o:p></o:p>
Next Rng <o:p></o:p>
End Sub <o:p></o:p>
<o:p></o:p>
<o:p>This macro is used to put a round formula onto any formula. However the major problem is that if I do not select at least 2 cells, it applies the macro to the WHOLE sheet which is not what I need.</o:p>
<o:p></o:p>
<o:p>Would appreciate any help</o:p>
<o:p></o:p>
<o:p>Cheers</o:p>
<o:p></o:p>
<o:p>GusC</o:p>
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hello and welcome to MrExcel.

For #1 try

Code:
Selection.NumberFormat = "#,##0;[Red](#,##0);-;@"
 
Upvote 0
Thats great VoG.
I love this website.
Anyone got any ideas re the Round Formula selection issue
 
Upvote 0

Forum statistics

Threads
1,221,507
Messages
6,160,216
Members
451,630
Latest member
zxhathust

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top