Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel - want to "Bold" the row. 1

Status
Not open for further replies.

srogers

Technical User
Aug 15, 2000
201
0
0
US
In an Excel 2000 application I gave the user a button to click when they are ready to total the section they are working on (I use a Case statement for placement of the formulas. An array is also involved because I am adding this Total row to each of 15 sheets in the workbook). The formula part works fine.

I also want each total row on each sheet to be in bold. I format the sheet with lines which works - but the bold part isn't working. I tried recording it and using that but maybe because of the array it isn't right?

I tried: Selection.Font.Bold = True
which doesn't work and I also tried adding:
.Font.Bold = True
where it does the border lines but that doesn't work either. Only the lines appear.

See part of what I have below.
Thanks for any ideas you have.



Case 36 'Period 6
Worksheets(vArrSh(sh)).Range("F36").Value = "=Sum(F32:F35)"
Worksheets(vArrSh(sh)).Range("G36").Value = "=B36/F36"
Worksheets(vArrSh(sh)).Range("H36").Value = "=D36/F36"
Selection.Font.Bold = True
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
.Font.Bold = True
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
 
Hi,

I note that your code acts only on a selection range. What is the selection? Is there any reason for using a selection range rather than simply defining the range?

Having said that, I think the basic problem is with your bold statement. I think it should be something along the lines of:

Selection.Font.FontStyle = "Bold"

Cheers
 
Honestly - I'm not sure how it is doing the selection. I'm sure I got that from recording it first. And if I do define the range then I'm not sure how to re-word the syntax. I don't think it's the following because I just tried it:
With Range(A36:H36).Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With

Is this: Selection.Font.FontStyle = "Bold"
a separate line outside the "With" statement?

Thank you -
 
OK, for Range(A36:H36) you could bold the font using:
Range(A36:H36).Font.FontStyle = "Bold"
No selection required.

So, you could use:
With Range(A36:H36).Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Range(A36:H36).Font.FontStyle = "Bold"

or

With Range(A36:H36)
With .Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
.Font.FontStyle = "Bold"
End With

Cheers
 
erm - what's with this "Fontstyle" nonsense.

Code for setting font to bold is

Range("A1").font.bold = true

However, what is almost certainly happening is that your selection is NOT where you are entering the formulae

Within your "Case 36" select case, you can use

rows(36).entirerow.font.bold = true

Rgds, Geoff

Never test the depth of water with both feet

Help us to help you by reading FAQ222-2244 before you ask a question
 
From the Excel vba help file:

FontStyle Property

Returns or sets the font style. Read/write String.

Remarks

Changing this property may affect other Font properties (such as Bold and Italic).


FontStyle Property Example

This example sets the font style for cell A1 on Sheet1 to bold and italic.

Worksheets("Sheet1").Range("A1").Font.FontStyle = "Bold Italic"
 
My point was that there is no need to use the Fontstyle property as the FONT.BOLD = TRUE will work fine - that is not the issue here. The issue is:

Selection.Font.Bold = True

should be qualified as

rows(36).Font.Bold = True


Rgds, Geoff

Never test the depth of water with both feet

Help us to help you by reading FAQ222-2244 before you ask a question
 
Hi macropod,

Geoff (and srogers' original code) is right. One should use .Font.Bold = True to bold the text.

Setting .Font.FontStyle = "Bold" will bold the text BUT it will also remove all Italics which is probably a bigger effect that is required.

I'm not sure about the original problem. It seems likely that the Selection is wrong, but the questioner says that setting the Borders works (and that uses the Selection).

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Tony and Geoff -
Thanks so much - you are always there with thoughtful answers (and you are right so much of the time I can't help but think the error is still with me). But I tried both the lines below (one at a time) and only the total row on sheet A turned out Bold each time. Every time I tried it sheets B thru O were not Bold.

Range("A31:H31").Font.Bold = True
and
Rows(31).EntireRow.Font.Bold = True

Macropod,
I have to give you a star because best way or not, the following line worked. The total row on each sheet is bold.
Range("A31:H31").Font.FontStyle = "Bold"

Thanks so much to everyone for replying.
 
Oh sure. At home it worked every time. Now I'm at the office and not every total row is bold. I think it may have something to do with the active sheet. I have 3 loops and before each one I activated the first sheet it would affect. The total row on that sheet is bold but the ones that follow are not. Meanwhile I'm trying all the other variations of bolding the row - none of which are working yet.
 
I added this:

Worksheets(vArrSh(sh)).Activate

after each For statement and now they all Bold.

Thanks to all. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top