ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Changing font size of cells via VBA code (https://www.excelbanter.com/excel-programming/367715-changing-font-size-cells-via-vba-code.html)

James

Changing font size of cells via VBA code
 
I am having a problem with Excel hanging up and crashing when executing the
following lines of code. Based upon breakpoints that I have set, it more
specifically looks like it always hangs up on the line of code that changes
the font size.

Does anybody have any insight into why this happens or have any suggestions
of how I can modify my code to keep this from happening?

Thanks,
James

With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = True
.MergeCells = True
.Interior.ColorIndex = 4
End With

With Selection.Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 10
End With

With Selection.Borders
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With

Selection.Borders(xlTop).LineStyle = xlNone

Peter T

Changing font size of cells via VBA code
 
Suspicion fell on the merge but your code works fine for me, not sure why
not for you. Try doing the Font stuff first. Or, after merging -

With Selection(1).Font

Regards,
Peter T

"James" wrote in message
...
I am having a problem with Excel hanging up and crashing when executing

the
following lines of code. Based upon breakpoints that I have set, it more
specifically looks like it always hangs up on the line of code that

changes
the font size.

Does anybody have any insight into why this happens or have any

suggestions
of how I can modify my code to keep this from happening?

Thanks,
James

With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = True
.MergeCells = True
.Interior.ColorIndex = 4
End With

With Selection.Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 10
End With

With Selection.Borders
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With

Selection.Borders(xlTop).LineStyle = xlNone




moon[_5_]

Changing font size of cells via VBA code
 
Replace .FontStyle = "Bold" with .Bold = True




"James" schreef in bericht
...
I am having a problem with Excel hanging up and crashing when executing the
following lines of code. Based upon breakpoints that I have set, it more
specifically looks like it always hangs up on the line of code that
changes
the font size.

Does anybody have any insight into why this happens or have any
suggestions
of how I can modify my code to keep this from happening?

Thanks,
James

With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = True
.MergeCells = True
.Interior.ColorIndex = 4
End With

With Selection.Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 10
End With

With Selection.Borders
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With

Selection.Borders(xlTop).LineStyle = xlNone




James

Changing font size of cells via VBA code
 
Thanks for the suggestions from both of you. The code runs perfectly now.

James

"moon" wrote:

Replace .FontStyle = "Bold" with .Bold = True




"James" schreef in bericht
...
I am having a problem with Excel hanging up and crashing when executing the
following lines of code. Based upon breakpoints that I have set, it more
specifically looks like it always hangs up on the line of code that
changes
the font size.

Does anybody have any insight into why this happens or have any
suggestions
of how I can modify my code to keep this from happening?

Thanks,
James

With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = True
.MergeCells = True
.Interior.ColorIndex = 4
End With

With Selection.Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 10
End With

With Selection.Borders
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With

Selection.Borders(xlTop).LineStyle = xlNone






All times are GMT +1. The time now is 10:17 AM.

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