AW: Diagonale in Zelle in Abhängigkeit
24.11.2013 12:15:28
Tino
Hallo,
hoffe habe dich richtig verstanden?!
Kannst mal so versuchen/testen.
Sub Test1()
Dim nCol&
Dim rng As Range
Dim objLinie As Shape
Dim oTabelle As Worksheet
'Tabelle anpassen
Set oTabelle = Tabelle1
On Error GoTo ErrorHandler:
With Application
.ScreenUpdating = False
.EnableEvents = False
With oTabelle
Kill_Linie oTabelle
nCol = .Cells(5, .Columns.Count).End(xlToLeft).Column
For nCol = 1 To nCol
If .Cells(5, nCol) <> "" Then
Set rng = FindLeerZelle(.Range(.Cells(5, nCol), .Cells(150, nCol)))
If Not rng Is Nothing Then
For Each rng In rng.Areas
With rng
Set objLinie = oTabelle.Shapes.AddLine(.Left + .Width / 2, _
.Top, _
.Left + .Width / 2, _
.Cells(.Rows.Count, 1).Top + .Cells(.Rows.Count, 1).Height)
End With
'sonstige Formatierung
With objLinie.Line
.Weight = 2
.ForeColor.RGB = RGB(164, 166, 164)
End With
Next rng
End If
End If
Next nCol
End With
ErrorHandler:
.ScreenUpdating = True
.EnableEvents = True
End With
If Err.Number <> 0 Then
MsgBox Err.Description, _
vbCritical + vbMsgBoxSetForeground + vbMsgBoxHelpButton, _
"Error: " & Err.Number, Err.HelpFile, Err.HelpContext
End If
End Sub
Private Function FindLeerZelle(rngBereich As Range) As Range
On Error Resume Next
Set FindLeerZelle = rngBereich.SpecialCells(xlCellTypeBlanks)
End Function
Private Sub Kill_Linie(objTabelle As Object)
Dim oShape As Shape
For Each oShape In Tabelle1.Shapes
If oShape.Type = msoLine Then oShape.Delete
Next oShape
End Sub
Gruß Tino