Zellen ausrichten mit VBA
15.12.2003 19:28:31
Stefan Glander
ich habe foldenden Code in einem Modul hinterlegt:Option Explicit
Option Explicit
Sub unColour_Cells(myR As Integer)
' myR für die Zeile wird von der Checkbox übergeben
' 4 und 8 kennzeichnen die Spalten die du markieren willst
With Range(Cells(myR, 12), Cells(myR, 16))
.Interior.ColorIndex = 47 '3 = Rot
'Die Rahmen kannst du ja anpassen
With .Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 55
End With
With .Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 55
End With
With .Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 55
End With
With .Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 55
End With
With .Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 55
End With
With .Font
.Name = "Thahoma"
.FontStyle = "Standard"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 2
End With
End With
End Sub
Nun möchte ich auch noch das die betreffenden Zellen auch noch Vertikal zentriert werden.
wenn ich nun folgenden Code anfüge bekomme ich aber eine Fehlermeldung
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Code eingefügt mit Syntaxhighlighter 2.5
Kann mir jemand sagen wie der Code richtig lauten muss?
Gruss
Stefan Glander