ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to format a range of cells from VB (https://www.excelbanter.com/excel-programming/329191-how-format-range-cells-vbulletin.html)

Wayne Ware

How to format a range of cells from VB
 
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

Bob Umlas[_3_]

How to format a range of cells from VB
 
Selection.NumberFormat = "#,##0.00"
or
Range("A1:E3").NumberFormat = "$#,##0"
for example...
Is this what you're looking for?


"Wayne Ware" wrote in message
...
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




Andrew B[_4_]

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



All times are GMT +1. The time now is 05:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com