ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Changin Cell Formats using VBA (https://www.excelbanter.com/excel-discussion-misc-queries/67296-changin-cell-formats-using-vba.html)

Michael

Changin Cell Formats using VBA
 
Hey Guys.

I was wondering if someone could help me.

I am writing VB code for a budgetary and forecasting tool. I have the code
written to do the analysis, and then create a summary table with all the
information in it. However, the cells are formatted correctly so each time I
run it, I have make some cosmetic changes. I know you can do this using VB,
but I do not know how.

I need to:
- Change the format of a range from a number to currency.
- Change the format of a range from a number to a percentage.
- Add all around borders for a range.

I greatly appreciate any assistance you could provide.

Thanks,

-Michael

Gary''s Student

Changin Cell Formats using VBA
 
Using the Macro Recorder:


Sub Macro2()
Range("G1").Select
Selection.NumberFormat = "$#,##0.00"
Range("G2").Select
Selection.NumberFormat = "0.00%"


Range("G1:G2").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
End Sub
--
Gary's Student


"Michael" wrote:

Hey Guys.

I was wondering if someone could help me.

I am writing VB code for a budgetary and forecasting tool. I have the code
written to do the analysis, and then create a summary table with all the
information in it. However, the cells are formatted correctly so each time I
run it, I have make some cosmetic changes. I know you can do this using VB,
but I do not know how.

I need to:
- Change the format of a range from a number to currency.
- Change the format of a range from a number to a percentage.
- Add all around borders for a range.

I greatly appreciate any assistance you could provide.

Thanks,

-Michael



All times are GMT +1. The time now is 06:33 AM.

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