Clever-Excel-Forum

Normale Version: Aktive Zeile markieren mit VBA
Du siehst gerade eine vereinfachte Darstellung unserer Inhalte. Normale Ansicht mit richtiger Formatierung.
Hallo Leute!

Ich habe mit folgendem Script die aktuelle Zeile markiert:


PHP-Code:
Option Explicit
    Dim prevCell 
As Range
   Dim myDic 
As Object
   
Private Sub Workbook_BeforeClose(Cancel As Boolean)
   Set myDic Nothing
End Sub

Private Sub Workbook_Open()
   Set myDic CreateObject("Scripting.Dictionary")
   myDic.Add "Betriebe"5    
   myDic
.Add "Postbuch"11 
End Sub



Private Sub Workbook_SheetActivate(ByVal Sh As Object)
   If Sh.Type xlWorksheet Then
      Set prevCell 
ActiveCell
   End 
If
End Sub

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object_
   ByVal Target 
As Range)
   If Sh.Type xlWorksheet Then
      
If Not prevCell Is Nothing Then
         
'myDic(Sh.Name) liefert die entsprechende bis-Spalte als Zahlenwert
         Sh.Cells(prevCell.Row, 1).Resize(1, myDic(Sh.Name)).Interior.ColorIndex = xlColorIndexNone
      End If
      Sh.Cells(Target.Row, 1).Resize(1, myDic(Sh.Name)).Interior.Color = RGB(0, 255, 0)
      Set prevCell = Target
   End If
End Sub 


Sobald ich aber eine Zelle dabei hab, die geschützt ist kommt immer ein Laufzeitfehler.

Wisst ihr vielleicht wie ich das abändern kann? die gesperrte Zelle soll genauso wie die anderen farblich hinterlegt werden. Sie kann nur nicht bearbeitet werden.

LG
Hallo Hannibal,

schaue Dir mal die Optionen vom Blattschutz an. Da kannst Du u.a. das Formatieren erlauben.