That is great and I understand. However, I forgot about the cell background
fill.
Dim vCellBackGroundFill
vCellBackGroundFill = RGB(50, 100, 150)
Also, how did you get the number 34 for for the color index?
My font name is: "Trebuchet MS"
This seems to be an issue for some reason?
is this correct?
Thanks
"CellShocked" wrote in message
...
On Mon, 25 Feb 2013 20:43:41 -0500, GS wrote:
After serious thinking JCO wrote :
Not quite working. Can you tell me how to Dim the items below. Example
Dim sFontName As Variant
Dim iFontSize as Integer
Dim sFontColor As Variant
...
code
...
With Selection.Font
.Name = sFontName
.Size = sFontSize
.ColorIndex = sFontColor
End With
It's a good idea to establish for yourself a *consistent* variable
naming discipline so as to obviate any confusion resulting from a
non-discipline approach. For example, you declared "iFontSize" as type
"integer" but your code uses "sFontSize" as the value to assign to
fontsize.
The very 1st thing you want to do is to set variable declaration as a
requirement in the *Code Settings* section on the *Editor* tab of the
*Options* dialog.
Now you will have the following statement appear at the top of code
windows when you create new code for the 1st time...
Option Explicit
..because the VB IDE will auto-insert this for you. You will, however,
have to add it manually in any code window that already has code.
Now, let's review your declares...
Dim vFontName, vFontSize, vFontColorNdx
..which are all type "Variant" as per the ObjectBrowser description of
these Font properties. Note the prefix I used is "v" to indicate they
are type "Variant". Note also that VBA types these as Variant because
type was not specified.
Now that we have variables to use, we need to assign values to them...
vFontName = "Arial": vFontSize = 10: vFontColorNdx = 34
Note that I appended "Ndx" to vFontColor so it's clear that we're
setting the ColorIndex property as opposed to the Color property.
Now we can assign the values stored in the variables...
With Selection.Font
.Name = vFontName: .Size = vFontSize: .ColorIndex = vFontColorNdx
End With 'Selection.Font
Alternative approach:
You could declare these as constants if they never change...
Const vFontName As Variant = "Arial"
Const vFontSize As Variant = 10
Const vFontColorNdx As Variant = 34
..which saves some extra coding doing it the other way.<g
Great post on variables.
How do I change the default link font and color, and how do I change
the default "link" hover text box formatting?
Declare it at the start of a workbook development?