How to format a range of cells from VB
Hi Wayne
Here are some examples of formatting through VBA.
You don't necessarily have to select cells first before formatting them.
I learnt how to format by recording macros and then studying the code.
Macro1 below is an exmple of this.
HTH
Andrew B
Cells are formatted without selection here.
ActiveSheet.Range("D43:CH58") = ""
ActiveSheet.Range("D43:CH58").Interior.ColorIndex = 15
A recorded macro.
Sub Macro1()
'
Range("B4:B19").Select
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Columns("B:B").ColumnWidth = 10
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
Selection.NumberFormat = "0.0"
Selection.Font.Bold = True
End Sub
Wayne Ware wrote:
I am new to Visual Basic for please forgive the "rookie" question.
I have a range of cells in an Excel spreadsheet that I need to format
from a Visual Basic program. Can someone provide a brief example of
how to do this? Or point me to some online documentation that would
help?
Thanks in advance.
Wayne
|