Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
892to896
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
892to896
892to896
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

Zelleninhalte in Kommentare umwandeln und dann...?

Zelleninhalte in Kommentare umwandeln und dann...?
31.07.2007 20:56:20
Selma
Hallo Leute,
ich möchte gern per VBA in Spalte Z ab Zeile 2 bis letzte Zellen mit Inhalt (bezogen auf Spalte Z) die Zelleninhalte (nur wenn Inhalt vorhanden ist) in Kommentare umwandeln.
Danach soll in Zellen (nur bei umgewandelten) der Text "siehe Kommentar" eingetragen werden.
Die Kommentare sollen in Schriftgröße 12 und mit automatische Größe (.AutoSize = True) dargestellt werden.
Wie mache ich das ?
Vielen Dank im Voraus.
Liebe Grüße
Selma

9
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Zelleninhalte in Kommentare umwandeln und dann
31.07.2007 21:51:43
Beverly
Hi Selma,
versuche es mit diiesem Code

Sub kommentare_einfuegen()
Dim loZeile As Long
Dim coKommentar As Comment
Dim strText As String
For loZeile = 2 To IIf(IsEmpty(Cells(Rows.Count, 26)), Cells(Rows.Count, 26).End(xlUp).Row,  _
Rows.Count)
If Cells(loZeile, 26)  "" Then
strText = Cells(loZeile, 26)
Cells(loZeile, 26).AddComment strText
Set coKommentar = Cells(loZeile, 26).Comment
With coKommentar.Shape
With .DrawingObject.Font
.Size = 12
.FontStyle = "Arial"
End With
.OLEFormat.Object.AutoSize = True
End With
Cells(loZeile, 26) = "siehe Kommentar"
End If
Next loZeile
Set coKommentar = Nothing
End Sub


________________________________________

Anzeige
AW: Zelleninhalte in Kommentare umwandeln und dann
31.07.2007 22:02:00
Selma
Hallo Karin,
das Makro bleibt hier "Cells(loZeile, 26).AddComment strText" stehen.
LG
Selma

AW: Zelleninhalte in Kommentare umwandeln und dann
31.07.2007 22:55:49
Ramses
Hallo
probiers mal damit
Option Explicit

Sub SetValue_to_Comment()
    Dim lastRow As Long, suchCol As Integer
    Dim myCom As Object
    Dim comTip As String
    Dim comSet As Boolean
    '******************
    'Variablen
    comTip = "Siehe Kommentar"
    suchCol = 26
    '******************
    For lastRow = 2 To Cells(Rows.Count, suchCol).End(xlUp).Row
        comSet = False
        With Cells(lastRow, suchCol)
            If .Value <> "" And UCase(.Value) <> UCase(comTip) And .Comment Is Nothing Then
                .AddComment
                .Comment.Text Text:="" & .Value & ""
                .Value = comTip
                comSet = True
            Else
                If .Value <> "" And UCase(.Value) <> UCase(comTip) Then
                    .Comment.Text Text:="" & .Value & ""
                    .Value = comTip
                    comSet = True
                End If
            End If
            If comSet = True Then
                Set myCom = Cells(lastRow, suchCol).Comment.Shape
                With myCom
                    With .DrawingObject.Font
                        .Size = 12
                        .FontStyle = "Arial"
                    End With
                    .OLEFormat.Object.AutoSize = True
                End With
            End If
        End With
    Next lastRow
    Set myCom = Nothing
End Sub

Anzeige
AW: Zelleninhalte in Kommentare umwandeln und dann
31.07.2007 23:44:40
Selma
Hallo Rainer,
vielen Dank es funktioniert prima....
Eine Frage noch:
wenn ich das Makro NUR auf die markierten Zellenbereich anwenden möchte, was muss noch geändert werden? Geht das überhaupt?
Liebe Grüße
Selma

AW: Zelleninhalte in Kommentare umwandeln und dann
01.08.2007 00:09:35
Ramses
Hallo
Du solltest dir vorher den Inhalt deiner Frage überlegen und nicht anschliessend die Anforderung ändern :-)
Hier "AllInclusive":
Option Explicit

Sub SetValue_to_Comment_in_free_Selection()
    Dim myC As Range, suchCol As Integer, lastRow As Long
    Dim myCom As Object
    Dim comTip As String
    Dim comSet As Boolean
    Dim Qe As Integer
    '******************
    'Variablen
    comTip = "Siehe Kommentar"
    suchCol = 2
    '******************
    If Selection.Cells.Count >= 1 Then
        Qe = MsgBox("Möchten Sie Werte aus dem selektierten Bereich:" & vbCrLf & _
        Selection.Address & vbCrLf & _
        "ersetzen, oder die Daten in der Spalte: " & vbCrLf & _
        "" & Columns(suchCol).Address & "" & vbCrLf & _
        "umwandeln ?" & vbCrLf & _
        "Ausgewählten Bereich """ & Selection.Address & """ umwandeln = ""JA""" & vbCrLf & _
        "Spalte """ & Columns(suchCol).Address & " "" umwandeln = ""NEIN""", vbQuestion + vbYesNoCancel + vbDefaultButton1, _
        "Zellwerte in Kommentare umwandeln")
            If Qe = vbCancel Then Exit Sub
        If Qe = vbNo Then
            For lastRow = 2 To Cells(Rows.Count, suchCol).End(xlUp).Row
                comSet = False
                With Cells(lastRow, suchCol)
                    If .Value <> "" And UCase(.Value) <> UCase(comTip) Then
                        If .Comment Is Nothing Then
                            .AddComment
                        End If
                        .Comment.Text Text:="" & .Value & ""
                        .Value = comTip
                        comSet = True
                    End If
                    If comSet = True Then
                        Set myCom = Cells(lastRow, suchCol).Comment.Shape
                        With myCom
                            With .DrawingObject.Font
                                .Size = 12
                                .FontStyle = "Arial"
                            End With
                            .OLEFormat.Object.AutoSize = True
                        End With
                    End If
                End With
            Next lastRow
        Else
            For Each myC In Selection
                comSet = False
                With myC
                    If .Value <> "" And UCase(.Value) <> UCase(comTip) Then
                        If .Comment Is Nothing Then
                            .AddComment
                        End If
                        .Comment.Text Text:="" & .Value & ""
                        .Value = comTip
                        comSet = True
                    End If
                    If comSet = True Then
                        Set myCom = myC.Comment.Shape
                        With myCom
                            With .DrawingObject.Font
                                .Size = 12
                                .FontStyle = "Arial"
                            End With
                            .OLEFormat.Object.AutoSize = True
                        End With
                    End If
                End With
            Next myC
        End If
    End If
    Set myCom = Nothing
    Set myC = Nothing
End Sub

Gruss Rainer

Anzeige
AW: Zelleninhalte in Kommentare umwandeln und dann
01.08.2007 00:27:07
Selma
Hallo Rainer,
vielen vielen Dank für Deine Hilfe....
Ich wünsche Dir eine gute Nacht....
Liebe Grüße
Selma

Etwas verkürzt...
31.07.2007 23:46:00
Ramses
Hallo
Nimm diese Variante.
Eine Abfrage war überflüssig
Option Explicit

Sub SetValue_to_Comment()
    Dim lastRow As Long, suchCol As Integer
    Dim myCom As Object
    Dim comTip As String
    Dim comSet As Boolean
    '******************
    'Variablen
    comTip = "Siehe Kommentar"
    suchCol = 2
    '******************
    For lastRow = 2 To Cells(Rows.Count, suchCol).End(xlUp).Row
        comSet = False
        With Cells(lastRow, suchCol)
            If .Value <> "" And UCase(.Value) <> UCase(comTip) Then
                If .Comment Is Nothing Then
                    .AddComment
                End If
                .Comment.Text Text:="" & .Value & ""
                .Value = comTip
                comSet = True
            End If
            If comSet = True Then
                Set myCom = Cells(lastRow, suchCol).Comment.Shape
                With myCom
                    With .DrawingObject.Font
                        .Size = 12
                        .FontStyle = "Arial"
                    End With
                    .OLEFormat.Object.AutoSize = True
                End With
            End If
        End With
    Next lastRow
    Set myCom = Nothing
End Sub

Gruss Rainer

Anzeige
AW: Zelleninhalte in Kommentare umwandeln und dann
01.08.2007 05:46:00
Beverly
Hi Selma,
du hattest nichts davon geschrieben, dass in manchen Zellen schon Kommentare stehen

Sub kommentare_einfuegen()
Dim loZeile As Long
Dim coKommentar As Comment
Dim strText As String
For loZeile = 2 To IIf(IsEmpty(Cells(Rows.Count, 26)), Cells(Rows.Count, 26).End(xlUp).Row,  _
Rows.Count)
If Cells(loZeile, 26)  "" Then
If Cells(loZeile, 26).Comment Is Nothing Then
strText = Cells(loZeile, 26)
Cells(loZeile, 26).AddComment strText
Set coKommentar = Cells(loZeile, 26).Comment
With coKommentar.Shape
With .DrawingObject.Font
.Size = 12
.FontStyle = "Arial"
End With
.OLEFormat.Object.AutoSize = True
End With
Cells(loZeile, 26) = "siehe Kommentar"
End If
End If
Next loZeile
Set coKommentar = Nothing
End Sub


Bis später,
Karin

Anzeige
AW: Zelleninhalte in Kommentare umwandeln und dann
01.08.2007 09:54:00
Selma
Vielen Dank Karin.
Liebe Grüße
Selma

306 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige