Hallo,
ein Kommentar will einen String haben. Ändere die entsprechenden Zeilen zu:
If Not IsEmpty(.Range("Q" & lngZeile)) Then
.Range("D" & lngZeile).AddComment Range("Q" & lngZeile).Text
End If
Claus
Dieser Browser wird nicht mehr unterstützt.
Führen Sie ein Upgrade auf Microsoft Edge durch, um die neuesten Features, Sicherheitsupdates und den technischen Support zu nutzen.
Hallo zusammen,
meine Situation ist, dass mittels VBA einer Zelle eine Notiz hinzufügen möchte, dessen Inhalt aus einer anderen Zelle kommt. Ich habe mir bereits das Makro erstellt, das auch grundsätzlich funktioniert. Ich vermute die Ursache eher bei Excel selbst.
| Spalte D | Spalte Q |
|---|---|
| Text | .211790034 |
| --- | --- |
| Text | B18BJ6 |
| --- | --- |
| Text | B211790034 |
| --- | --- |
| Text | B18BJ6 |
| --- | --- |
| Text | 0211790034 |
| --- | --- |
| Text | B18BJ6 |
| --- | --- |
Ein Fileupload ist von hier aus nicht möglich, weshalb ich das kurz beschreibe. Das Problem stellt sich nur bei dem hervorgehobenen Inhalt. Ich habe in Zeile eins und drei testweise mal ein Zeichen ("." und "B") vorangestellt, womit mein Makro auch tadellos funktioniert. Die Zellen in Spalte Q haben das benutzerdefinierte Format "0"###""###. Es ist jedoch auch unerheblich, ob ich das Format in Standard, Text oder Zahl ändere. Es scheint so, als ob Excel das einfach nicht erkennt.
Mein Makro sieht folgendermaßen aus.
Sub ZelleInKommentar()
Dim lngZeile As Long, lngZeileMax As Long
With Tabelle1
lngZeileMax = .UsedRange.Rows.Count
For lngZeile = lngZeileMax To 1 Step -1
Select Case .Range("B" & lngZeile).Value
Case "H.27", "ICR", "KET", "Eching", "Garching"
On Error Resume Next
If Not IsEmpty(.Range("Q" & lngZeile).Value) Then
.Range("D" & lngZeile).AddComment
.Range("D" & lngZeile).Comment.Text Text:=.Range("Q" & lngZeile).Value
End If
End Select
Next lngZeile
End With
End Sub
Ich habe mir mit den Testdaten einmal eine Testdatei gebaut, diese als neue Datei gespeichert, anschließend in .zip umbenannt und entpackt. Die comments.xml hat folgenden Inhalt.
<comments xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:xr="http://schemas.microsoft.com/office/spreadsheetml/2014/revision" mc:Ignorable="xr">
<authors><author>Rankl Markus</author></authors>
<commentList> <comment ref="D1" authorId="0" shapeId="0" xr:uid="{B5E180FD-B987-45FE-A707-4A123A221107}"> <text> <r> <rPr> <sz val="9"/><color indexed="81"/><rFont val="Segoe UI"/><family val="2"/> </rPr> <t>.211790034</t> </r> </text> </comment>
<comment ref="D2" authorId="0" shapeId="0" xr:uid="{4AF3D89A-9866-4902-AC5D-8B148131FE3C}"> <text> <r> <rPr> <sz val="9"/><color indexed="81"/><rFont val="Segoe UI"/><family val="2"/> </rPr> <t>B18BJ6</t> </r> </text> </comment>
<comment ref="D3" authorId="0" shapeId="0" xr:uid="{8198BB5A-FAC5-41ED-8B0B-B77B2F282EEA}"> <text> <r> <rPr> <sz val="9"/><color indexed="81"/><rFont val="Segoe UI"/><family val="2"/> </rPr> <t>B211790034</t> </r> </text> </comment>
<comment ref="D4" authorId="0" shapeId="0" xr:uid="{D2E94610-1466-48FD-9848-B8703E668F29}"> <text> <r> <rPr> <sz val="9"/><color indexed="81"/><rFont val="Segoe UI"/><family val="2"/> </rPr> <t>B18BJ6</t> </r> </text> </comment>
<comment ref="D5" authorId="0" shapeId="0" xr:uid="{6BA2A877-94A9-4987-94E9-5F8B4751761D}"><text/></comment>
<comment ref="D6" authorId="0" shapeId="0" xr:uid="{B81C2C8E-D391-47E7-B7DD-4C4E51A240EB}"> <text> <r> <rPr> <sz val="9"/><color indexed="81"/><rFont val="Segoe UI"/><family val="2"/> </rPr> <t>B18BJ6</t> </r> </text> </comment> </commentList> </comments>
Der Abschnitt von Zelle D5 (Zelle Q5 ist der problematische Inhalt) ist leer. Da das Makro grundsätzlich seine Arbeit verrichtet und das ausschließlich mit dem hervorgehobenen Inhalt nicht funktioniert, vermute ich die Ursache bei Excel. Hat jemand eine Antwort darauf, weshalb Excel oder das Makro den Inhalt aus Zelle Q5 ignoriert?
Gesperrte Frage. Diese Frage wurde aus der Microsoft-Support-Community migriert. Sie können darüber abstimmen, ob sie hilfreich ist, aber Sie können keine Kommentare oder Antworten hinzufügen oder der Frage folgen.
Hallo,
ein Kommentar will einen String haben. Ändere die entsprechenden Zeilen zu:
If Not IsEmpty(.Range("Q" & lngZeile)) Then
.Range("D" & lngZeile).AddComment Range("Q" & lngZeile).Text
End If
Claus
Hat funktioniert. Vielen Dank.