VBA NumberFormat with Special Characters

russellrichter

Board Regular
Joined
Mar 23, 2009
Messages
63
I have a VBA module in which I need to add formatting to a number based on several criteria. (Excel 2003). If a record in the worksheet meets these criteria, the cell should be displayed as a right-facing triangle (U+25BA), the number and a left-facing triangle (U+25C4).

I am able to do this by copying the characters from the character map and pasting them into the custom number formatting dialog boxes in Excel. But, I can't seem to get that same effect in VBA using the Alt+[NumPad] method. Even when I record the custom formatting as a macro, the recorded macro does not set the format as it was recorded, but instead sets it to "? 0 ?".

So, is it possible in the Selection.NumberFormat command to set a format using these special characters?

Thanks for the help!

Russ
Houston
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Something like this should work:
Code:
activecell.NumberFormat = chrw(&H25BA) & "0" & chrw(&H25C4)
 
Upvote 0
I have no idea if this will work, but it's worth a try. Create a Custom style (say myStyle) with this custom format. Now if your code, you can use something like
Code:
Range("$A$1").Style= "myStyle"

lenze
 
Upvote 0
Something like this should work:
Code:
activecell.NumberFormat = chrw(&H25BA) & "0" & chrw(&H25C4)
If it's okay, resurrecting this to see if I can find an answer to my own question. OP had left and right-facing arrows, what about up/down? Where would I find the codes for something like that? I've been searching the internet for probably 20 minutes and cannot find what I'm looking for. lol

For reference, this is what I'm trying to achieve in VBA

Excel Formula:
[Color10]$0.00▲;[Red]$0.00▼;
 
Upvote 0

Forum statistics

Threads
1,215,537
Messages
6,125,389
Members
449,222
Latest member
taner zz

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