Thema:
Re:SUUPER! Noch eine Frage zum Ausdehnen des Bereichs flat
Autor: Robo
Datum:03.09.19 18:36
Antwort auf:SUUPER! Noch eine Frage zum Ausdehnen des Bereichs von Maio4c

>Zum Beispiel alle Eintragungen von B1-B20 + C1-C20 + D1-D20

Das geht so:

Range("B1:D20")

also erst die obere linke Ecke und dann die untere rechte Ecke des Rechtecks angeben.


Falls Du mehrere nicht zusammenhängende Rechtecke hast, dann so:

Range("B1:D20,G30:J35")


Mir ist allerdings noch aufgefallen, dass das Skript nur funktioniert, wenn Du immer nur eine Zelle auf einmal änderst. Damit Du auch mehrere gleichzeitig ändern kannst (z.B. per Copy-Paste), muss das Skript so aussehen:


Private Sub Worksheet_Change(ByVal Target As Range)

   Dim Intersection As Range
   Dim CommentText As String
   Dim CurrentCell As Range
   
   Set Intersection = Intersect(Target, Range("B1:D20"))
   
   If Intersection Is Nothing Then Exit Sub
       
   CommentText = "letzte Änderung: " & Now()
       
   For Each CurrentCell In Intersection.Cells
       If CurrentCell.Comment Is Nothing Then
           CurrentCell.AddComment CommentText
       Else
           CurrentCell.Comment.Text CommentText
       End If
   Next CurrentCell
 
End Sub


< antworten >