Macro Error - Custom Cell Formatting

CubicleRot

New Member
Joined
Jan 17, 2019
Messages
1
I use several macros to help me convert numbers that do not work when I use custom cell formatting.

Below is an example of the VBA I use to multiply a cell value by 1000 or add formula to do so if formula is present.


Sub MUL1000()

Dim cell As Range
For Each cell In Selection
If Len(cell.Value) > 0 And Application.IsNumber(cell.Value) Then
If cell.HasFormula Then
cell.Formula = Replace(cell.Formula, "=", "=1000*(") & ")"
Else
cell.Value = 1000 * cell.Value
End If
End If
Next

End Sub


This code works great until I use custom formatting. Below is the custom formatting where I am encountering the error. The formatting is necessary to show a number that is in whole dollars in 1,000s.

_($* #,##0,_);_($* (#,##0,);_($* "-"??_);_(@_)


Please take it easy on me, I'm a novice. Thanks!
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi, welcome to the board.

I'm not a VBA expert, but just playing around with the macro recorder, I came up with this . . .

Code:
Sub MUL1000()

Dim cell As Range
For Each cell In Selection
If Len(cell.Value) > 0 And Application.IsNumber(cell.Value) Then
If cell.HasFormula Then
cell.Formula = Replace(cell.Formula, "=", "=1000*(") & ")"
cell.NumberFormat = "_(\$* #,##0,_);_(\$* (#,##0,);_(\$* ""-""??_);_(@_)"
Else
cell.Value = 1000 * cell.Value
cell.NumberFormat = "_(\$* #,##0,_);_(\$* (#,##0,);_(\$* ""-""??_);_(@_)"

End If
End If
Next

End Sub

There may well be better ways of doing this . . .
 
Upvote 0

Forum statistics

Threads
1,215,378
Messages
6,124,601
Members
449,173
Latest member
chandan4057

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