|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
||||
|
||||
|
set font style of a cell in excel
Hi all,
I' ve tried to set the font style of cell in excell to bold but everytime an error occurs. Code:
For Each aCell In Selection.Cells
If aCell.Value = "bla" Then
Range(aCell).Select
Selection.FontStyle = "Font"
End If
Next
The error message is: Code:
Run-time error '1004': Method 'Range' of Object '_Global failed' I appreciate every help. |
|
#2
|
||||
|
||||
|
You have propably figured this out by now, but if you havn't:
remember that aCell in your procedure is already a range, meaning you can't say range(aCell), just say aCell It isn't necessary to select a cell to change it's font. Code:
Dim aCell
For Each aCell In Selection.Cells
If aCell.Value = "bla" Then
aCell.Font.Bold = True
End If
Next
But anyway, I didn't know that you can loop through a selection the way you did, so thanks for the post ![]() |
|
#3
|
|||
|
|||
|
Your code is great, but how do you get it to apply to a different cell eg, if aCell refers to column A how do you get it to change the font of column C?
|
|
#4
|
||||
|
||||
|
aCell in the previous example refers to all the cells in the range that someone has selected. (And it only changes the fond for the cells that have a specific tests (in this example "bla") If you want it 2 change everything, take out the if statement)
If you want it 2 change the font 4 everything in a specific column, you can either select the column, e.g. Code:
Columns("C:C").Select
Dim aCell
For Each aCell In Selection.Cells
If aCell.Value = "bla" Then
aCell.Font.Bold = True
End If
Next
or just loop through the column, instead of the selection, e.g. Code:
Dim aCell
For Each aCell In Columns("C:C").Cells
If aCell.Value = "bla" Then
aCell.Font.Bold = True
End If
Next
Or you can do a specific number of rows in the column, e.g. Code:
for i = 1 to 8
cells(i, 3).font.bold = true
next i
This changes the font of the first 8 rows in column 3 (C) |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > set font style of a cell in excel |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|