Formatting Text to Italic AND Underlined to individually listed cells

C

Corey

I am trying to set the below listed cells to have the values displayed in
Italic AND Underlined.
Nothing seems to happen with the below???


ActiveSheet.Select
Dim rng As Range
Set rng = Range("A1,B1,D1,F1,B2,E2,B3,C3,D3,E3,F3,G3,H3,I3")
With rng
Font.Italic = False
Font.Underline = True
Range("A1").Value = "Roll#"
Range("B1").Value = "Customer"
Range("D1").Value = "Date"
Range("F1").Value = "Belt Type"
Range("B2").Value = "ST Job No."
Range("E2").Value = "Inspectors Names"
Range("B3").Value = "Item No."
Range("C3").Value = "Section Length"
Range("D3").Value = "Width"
Range("E3").Value = "Belt Type"
Range("F3").Value = "Top Cover"
Range("G3").Value = "Bottom Cover"
Range("H3").Value = "Event Type"
Range("I3").Value = "Comments/Stamp Id's"
End With


Did i miss something?
Corey....
 
D

Dave Peterson

If you want Italic, I would think that True would work better than False.

And watch your with/end with statements.

I bet you want something more like:

Option Explicit
Sub testme()

Dim rng As Range
Set rng = Range("A1,B1,D1,F1,B2,E2,B3,C3,D3,E3,F3,G3,H3,I3")
With rng
.Font.Italic = True
.Font.Underline = True
End With

Range("A1").Value = "Roll#"
Range("B1").Value = "Customer"
Range("D1").Value = "Date"
Range("F1").Value = "Belt Type"
Range("B2").Value = "ST Job No."
Range("E2").Value = "Inspectors Names"
Range("B3").Value = "Item No."
Range("C3").Value = "Section Length"
Range("D3").Value = "Width"
Range("E3").Value = "Belt Type"
Range("F3").Value = "Top Cover"
Range("G3").Value = "Bottom Cover"
Range("H3").Value = "Event Type"
Range("I3").Value = "Comments/Stamp Id's"

End Sub
 
C

Corey

Thanks Dave.
I did have the Italic set to TRUE but i changed it back to FALSE to see if i
accedently had the entire sheet in italic.
 
D

Dave Peterson

My bet is that you underlined/italicized different cells than you meant.

If you do this:

dim myRng as range
set myrng = range("b3")
'then use
with myrng
.range("b2").font.italic = true
'and more
end with

You're not formatting B2 of that worksheet, you're formatting the cell that
corresponds to the cell in myRng (B3 in my sample).

And activesheet.range("b3").range("B2") is the same as C4--it's one cell to the
right and one cell down.

That's why I moved the "End with" to its new location in the code.
 
D

Dave Peterson

This may be better:

You're not formatting B2 of that worksheet, you're formatting the cell that
corresponds to B2 if you assume the origin is myRng (B3 in my sample).

Instead of this:

You're not formatting B2 of that worksheet, you're formatting the cell that
corresponds to the cell in myRng (B3 in my sample).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top