Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why don't numeric cells have a .Characters() property?

With any text value, I can individually format each character and then copy that formatting to another cell by iterating over the Range.Characters() Collection.

However, if the cell is a number (even if the numberFormatting displays it as a string e.g. dates) then it does not expose a .Characters() property and, indeed, cannot be selectively formatted digit-by-digit.

Why does Excel display strings using Character objects but not numbers, even when the number is being displayed as a string?

like image 238
Kaz Avatar asked Nov 09 '22 17:11

Kaz


1 Answers

If you want to go around this, you may do the following:

In cell A1 put '123456 with the " ' " sign in front. Then write

range("A1").Characters(1,3).Font.Bold = true

It would take only the first three numbers, not taking into account the " ' " sign. Thus, the number is kind of displayed as a string, but you can still use it calculations e.g. A1 + 4 would give 123460.

like image 51
Vityata Avatar answered Nov 15 '22 07:11

Vityata