Help with formatting methods?
Hi there,
I'm very new at this so please bear with me....
I'm trying to find a method to color the background cells in my worksheet, format a cell so that it displays the date in the following format: "Nov-2005", and finally to format the number of decimal places displayed in some selected cells. Any ideas?
For the date problem, I'm not sure if I'm on the right track :
.range("A1").numberformat = " ????? "
Similarly for the decimal places prob, should I be using the .numberformat method??
Any help would be appreciated.
:wave:
Re: Help with formatting methods?
Quote:
Originally Posted by Beaver
I'm trying to find a method to color the background cells in my worksheet
To set the background colour to red...
VB Code:
Range("A1").Interior.ColorIndex = 3
Quote:
Originally Posted by Beaver
...format a cell so that it displays the date in the following format: "Nov-2005",...
VB Code:
Range("A1").NumberFormat = "mmm-yyyy"
Quote:
Originally Posted by Beaver
...to format the number of decimal places displayed in some selected cells.
Examples
for 2 decimal places with commas use
VB Code:
Range("A1").NumberFormat = "#,##0.00"
for 3 decimal places without commas
VB Code:
Range("A1").NumberFormat = "0.000"
Just change the range reference to which ever cells you need to format.
Re: Help with formatting methods?
I don't know if you've discovered this yet or not, but just in case not, here are a couple of examples of referencing cells programatically:
Code:
Option Explicit
Sub Macro1()
Dim aRow As Long
Dim aColumn As Long
aRow = 2
aColumn = 3
Cells(aRow, aColumn).Interior.ColorIndex = 3 'Cell C2
' -- or like this --
Cells(3, "B").Value = "TEST" 'Cell B3
End Sub
Good Learning and Good Programming!