How to sent for cell: font size=7,text format in VBA

  • Thread starter Thread starter netx
  • Start date Start date
N

netx

After I do .Range().Clear I lost "font size" and "text format" in Cells.
I wonder how to set in VBA:
- font size for cell
- formatting "text" for cell
Excel XP.

I am not sure about translation of above because I use Polish version of
Excel.

Thanks for help,

Mark
 
Mark -

Why not try running your macro recorder and looking at the code
afterwards? I put information in cell I18 and then changed the format
(e.g. italics, fontsize, borders, etc.). Here's what the code looks
like (in English). I also tested it - it works.

Sub Macro1()
Range("I18").Select
With Selection.Font
.Name = "AngsanaUPC"
.FontStyle = "Italic"
.Size = 24
.Strikethrough = True
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleDouble
.ColorIndex = xlAutomatic
End With
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Interior
.ColorIndex = 42
.Pattern = xlGray50
.PatternColorIndex = xlAutomatic
End With
End Sub
 
PS. Here's the code for pasting the formats from another cell: Put
the cursor on the cell that has the formatting you want, and the
following macro will copy those text formats into the new cell (I17)

Sub Macro2()
'
' Macro2 Macro
' Macro recorded 8/8/2005 by Jim Shoenfelt
'

'
Selection.Copy
Range("I17").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
End Sub
 
Maybe you want .range().clearcontents

That just erases the contents from the cell--like hitting the delete key.
 
Back
Top