Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1644to1648
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Kommentar mit VBA

Kommentar mit VBA
18.09.2018 11:35:44
Micha
Hallo,
mit meinem Makro schreibe ich, in diesem Fall TU, in jede markierte Zelle.
Dazu der Kommentar wer und wann.
Den Kommentar fügt das Makro aber nur in die Aktive Zelle. (So wie geschrieben)
Ich möchte aber das der Kommentar ebenfalls in jede markierte Zelle geschrieben wird.
Komme aber nicht dahinter.
Hoffe einer von euch hat eine Idee
Gruß Micha
Sub TU()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
ActiveSheet.Unprotect Password:="123"
Dim x As Object
Dim eingabe As String
eingabe = "TU"
For Each x In Selection
x.Value = eingabe
Next x
Selection.Font.Name = "Arial"
Selection.Font.Bold = True
Selection.Font.Size = 10
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 1841145
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With Selection.Font
.Color = -16777216
.TintAndShade = 0
End With
Dim strComment As String
With ActiveCell
If .Comment Is Nothing Then
strComment = TextBox1
.AddComment
With .Comment
.Text Text:=Application.UserName & ":" & Chr(10) & Format(Now, "DD" & "." & "MM" & "." & _
_
_
"YY") & strComment
.Shape.TextFrame.AutoSize = True
End With
Else
.Comment.Text Text:=.Comment.Text & Chr(10) & Application.UserName & Chr(10) & Format(Now, " _
_
_
DD" & "." & "MM" & "." & "YY") & strComment
End If
End With
ActiveSheet.Protect Password:="123" ', UserInterfaceOnly:=True, DrawingObjects:=False, Contents: _
_
_
=True, Scenarios:=False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

5
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Kommentar mit VBA
18.09.2018 11:45:01
PeterK
Hallo
Du mußt den "With ActiceCell" Block in die "For each x" Schleife packen und die With Anweisung durch "With x " ersetzen, dann sollte es funktionieren
AW: Kommentar mit VBA
18.09.2018 11:45:03
Torsten
also ich hab das gerade mal getestet. Der Code macht ganau das, was du moechtest.
Wenn man verschiedene Zellen markiert, wird der Kommentar in alle diese Zellen geschrieben.
AW: Kommentar mit VBA
18.09.2018 11:53:19
UweD
Hallo
TU kannst du ohne Schleife in alle selectierten Zellen schreiben.
Die Kommentare aber mit Schleife einzeln.
So gehts.
Modul1
Option Explicit 
 
Sub TU() 
 
    Application.DisplayAlerts = False 
    Application.ScreenUpdating = False 
     
    ActiveSheet.Unprotect Password:="123" 
    Dim x As Object 
    Dim eingabe As String 
        eingabe = "TU" 
     With Selection 
        .Value = eingabe 
      
        .Font.Name = "Arial" 
        .Font.Bold = True 
        .Font.Size = 10 
         
        With .Interior 
            .Pattern = xlSolid 
            .PatternColorIndex = xlAutomatic 
            .Color = 1841145 
            .TintAndShade = 0 
            .PatternTintAndShade = 0 
        End With 
     
        With .Font 
            .Color = -16777216 
            .TintAndShade = 0 
        End With 
         
    Dim strComment As String, Z 
     
    End With 
    For Each Z In Selection 
            With Z 
                If .Comment Is Nothing Then 
                    strComment = TextBox1 
                    .AddComment 
                    With .Comment 
                        .Text Text:=Application.UserName & ":" & Chr(10) & Format(Now, "DD" & "." & "MM" & "." & _
                            "YY") & strComment 
                        .Shape.TextFrame.AutoSize = True 
                    End With 
                Else 
                    .Comment.Text Text:=.Comment.Text & Chr(10) & Application.UserName & Chr(10) & Format(Now, _
                        "DD" & "." & "MM" & "." & "YY") & strComment 
                End If 
            End With 
        Next 
         
        ActiveSheet.Protect Password:="123" ', UserInterfaceOnly:=True, DrawingObjects:=False, Contents: _
            =True, Scenarios:=False 
     
    Application.DisplayAlerts = True 
    Application.ScreenUpdating = True 
     
End Sub 
 

LG UweD
Anzeige
AW: Kommentar mit VBA
18.09.2018 12:06:07
Micha
Funktioniert 1A
Danke für die schnelle Antwort
*Closed*
Danke für die Rückmeldung owT
18.09.2018 12:36:21
UweD
d

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige