Comments: Changing text with VBA - Running into limitations
Have code that will:
1) Look at each comment in a worksheet
2) Locate "(" and ")"
3) Decrement position from "(" until it gets to a char other than space
With those two positions, try to eliminate text between that last char and vbLF (exclusive).
The code seems to work correctly until it reaches the line containing f0605b". It can find the next "(" but cannot find the next ")".
Sub SheetCommentsNixParenths()
Dim cmt As Comment
Dim openChar As Integer
Dim closeChar As Integer
For Each cmt In ActiveSheet.Comments
CmtText = cmt.Shape.TextFrame.Characters.Text
Do While InStr(1, CmtText, "(") > 0
openChar = InStr(1, CmtText, "(")
closeChar = InStr(openChar, CmtText, ")")
If closeChar = 0 Then Exit Do
Do While Mid(CmtText, openChar, 1) = "(" Or Mid(CmtText, openChar, 1) = " "
openChar = openChar - 1
Loop
If openChar > 0 Then
cmt.Shape.TextFrame.Characters.Text = Mid(CmtText, 1, openChar) + Mid(CmtText, (closeChar + 1))
End If
CmtText = cmt.Shape.TextFrame.Characters.Text
Loop
Next
End Sub
Comment Contents:
NY 0218 F0101A
NY 0218 F0101B
NY 0218 F0101D
NY 0218 F0102C
NY 0218 F0104C
NY 0218 F0107D
NY 0218 f0108c
NY 0218 f0121a
NY 0218 f0213b
NY 0218 f0301
NY 0218 f0311d
NY 0218 f0316
NY 0218 f0319b
NY 0218 f0501
NY 0218 f0509b
NY 0218 f0605b (Not in MAP table)
NY 0218 f0706 (Not in MAP table)
NY 0218 f0722 (Not in MAP table)
NY 0218 f0913d_apr9 (Not in MAP table)
NY 0218 f1012 (Not in MAP table)
NY 0218 f1014 (Not in MAP table)
NY 0218 f1119b (Not in MAP table)
NY 0218 f1123a (Not in MAP table)
NY 0218 f1125b (Not in MAP table)
NY 0218 f1125d (Not in MAP table)
NY 0218 f1214 (Not in MAP table)
NY 0218 f1522 (Not in MAP table)
NY 0218 f1523d (Not in MAP table)
NY 0218 u0101b (Not in MAP table)
NY 0218 u0102c (Not in MAP table)
NY 0218 u0104c (Not in MAP table)
NY 0218 u0108c (Not in MAP table)
NY 0218 u0306a (Not in MAP table)
NY 0218 u0308d (Not in MAP table)
NY 0218 u0506d (Not in MAP table)
NY 0218 u1311c_rev (Not in MAP table)
The comment above used to have more "Not in MAP table", but code was able to remove those successfully. What can be done to process the rest of the text in this comment?
Recent comments
5 years 34 weeks ago
6 years 20 weeks ago
6 years 32 weeks ago
6 years 35 weeks ago
6 years 36 weeks ago
6 years 42 weeks ago
6 years 50 weeks ago
6 years 50 weeks ago
6 years 50 weeks ago
6 years 50 weeks ago