Finding Out about Ceil Formatting

A frequent spreadsheet task is applying formatting to a selected cell or a range. Your VBA procedure may need to find out the type of format applied to a particular worksheet cell. To retrieve the cell formatting, use the NumberFormat property:

?Range("A1").NumberFormat

Upon entering the above question in the Immediate window, Excel displays the word "General," which indicates that no special formatting was applied to the selected cell. To change the format of a cell using VBA, enter the following instruction:

Range("A1").NumberFormat = "$#,##0.00"

If you enter 125 in cell A1 after it has been formatted with the above VBA instruction, cell A1 will display $125.00. You can look up the necessary format codes in the Format Cells dialog box in the Microsoft Excel window (Format | Cells).

If the format you want to apply is not listed in the Format Cells dialog box, refer to the online help for guidelines on creating user-defined formats

Number j Alignment | Font | Border | Patterns | Protection j

Category;

General Number Currency mi

Number j Alignment | Font | Border | Patterns | Protection j

Category;

General Number Currency lype:

lype:

Accounting

Date

Time

Percentage

General

General g

Fraction Scientific Text'

Accounting

Date

Time

Percentage

Fraction Scientific Text'

Type the number format code, using one of the existing codes as a starting point.

Figure 2-26:

You can apply different

Type the number format code, using one of the existing codes as a starting point.

formatting to selected cells and ranges using the format codes

OK j Cancel j displayed in the Custom category in the Format Cells dialog box.

Was this article helpful?

0 0

Post a comment