+ Reply to Thread
Results 1 to 12 of 12

Add Text to all Existing Notes "Formerly known as Comments" in Merged Cells using VBA code

  1. #1
    Registered User
    Join Date
    10-21-2022
    Location
    us
    MS-Off Ver
    2017
    Posts
    7

    Add Text to all Existing Notes "Formerly known as Comments" in Merged Cells using VBA code

    I have over 100 blank Notes on a sheet in Excel I need to be able to update and add something to all of them and they are in merged cells. What is the VBA code to do this I can't figure it out?
    Any help would be appreciated.
    thanks, guys!


    Here is my code

    Sub My_FIX_Notes()

    ' This Macro will change all Note Comments to Transparent Blue Background & Bold White Text
    CommentCount = 0
    Dim MyComments As Comment
    Dim LArea As Long
    Dim fixed As Boolean
    fixed = False

    For Each MyComments In ActiveSheet.Comments
    With MyComments
    ' .Shape.Fill.OneColorGradient msoGradientDiagonalUp, 1, 0.23
    .Shape.AutoShapeType = msoShapeRoundedRectangle
    .Shape.TextFrame.Characters.Font.Name = "Arial"
    .Shape.TextFrame.Characters.Font.Size = 12
    .Shape.TextFrame.Characters.Font.ColorIndex = 2
    .Shape.Line.ForeColor.RGB = RGB(0, 0, 0)
    .Shape.Line.BackColor.RGB = RGB(255, 255, 255)
    .Shape.Fill.Visible = msoTrue
    .Shape.TextFrame.Characters.Font.Bold = True
    .Shape.Fill.BackColor.RGB = RGB(58, 82, 184)

    ' This fills background color of the Note and sets the transarancey to 0.04
    .Shape.Fill.ForeColor.RGB = RGB(85, 85, 110)
    .Shape.Fill.Transparency = 0.04

    'This Sets the With & Height of each Note Comment Hotkey
    MyComments.Shape.Width = 200
    MyComments.Shape.Height = 40

    CommentCount = CommentCount + 1

    End With
    Next 'comment


    If CommentCount > 0 Then
    'MsgBox ("A total of " & CommentCount & " comments in worksheet '" & MySheet.Name & "' of workbook '" & MyWorkbook.Name & "'" & Chr(13) & "were repositioned and resized.")

    MsgBox ("A Total Of " & CommentCount & "" & "Were change")

    fixed = True
    End If

    'Next
    ' Next MyWorkbook
    'thisfile.Activate


    If fixed = False Then
    MsgBox ("No comments were detected.")
    End If

    On Error GoTo 0

    Exit Sub
    End Sub


    Hotkey.jpg

  2. #2
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: Add Text to all Existing Notes "Formerly known as Comments" in Merged Cells using VBA

    Possibly

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    10-21-2022
    Location
    us
    MS-Off Ver
    2017
    Posts
    7

    Re: Add Text to all Existing Notes "Formerly known as Comments" in Merged Cells using VBA

    thank you that code adds that to the comments

    is there a way to clear the text in the comments I tried using a space in the " " but it didn't work
    thanks for your help by the way

  4. #4
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: Add Text to all Existing Notes "Formerly known as Comments" in Merged Cells using VBA

    Try

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-21-2022
    Location
    us
    MS-Off Ver
    2017
    Posts
    7

    Re: Add Text to all Existing Notes "Formerly known as Comments" in Merged Cells using VBA

    it works perfectly thank you so much for your help

  6. #6
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: Add Text to all Existing Notes "Formerly known as Comments" in Merged Cells using VBA

    Happy to help

  7. #7
    Registered User
    Join Date
    10-21-2022
    Location
    us
    MS-Off Ver
    2017
    Posts
    7

    Re: Add Text to all Existing Notes "Formerly known as Comments" in Merged Cells using VBA

    Sorry to keep bothering you I have one last problem when I add notes to the selected ranges it adds notes to the cells that are not merged, is there a command to keep this from happening I need it to add notes to just the merged cells that the user selects on the on-screen keyboard.

    thanks again!

    I'm currently using an input box for the user to make the selection

    Here is my full code

    Sub My_NoteReplace_InputBox()


    Dim xRg As Range
    Dim xRgEach As Range
    Dim xAddress As String
    Dim xText As String
    'On Error Resume Next

    ' This let's you select the Range of Cells to change
    xAddress = ActiveWindow.RangeSelection.Address
    Set xRg = Application.InputBox("Please select a range:", "Kutools For Excel", xAddress, , , , , 8)

    If xRg Is Nothing Then Exit Sub
    If xRg.Count > 1 Then
    Set xRg = xRg.SpecialCells(xlCellTypeVisible)
    End If

    ' This is where you enter what you want the Notes to have in them
    xRg.Select
    xText = InputBox("Enter Comment to Add" & vbCrLf & "Comment will be added to all cells in Selection: ", "Kutools For Excel")

    If xText = "" Then
    MsgBox "No comment added", vbInformation, "Kutools For Excel"

    If xRg.Select.MergeCells = False Then
    With xRgEach
    .DeleteComment
    End With

    End If

    Exit Sub

    End If

    For Each xRgEach In xRg


    With xRgEach
    .ClearComments
    .AddComment
    End With

    Next xRgEach


    ' This Macro will change all Note Comments to Transparent Blue Background & Bold White Text
    CommentCount = 0
    Dim MyComments As Comment
    Dim LArea As Long
    Dim fixed As Boolean
    fixed = False

    For Each MyComments In ActiveSheet.Comments
    With MyComments
    ' .Shape.Fill.OneColorGradient msoGradientDiagonalUp, 1, 0.23
    .Shape.AutoShapeType = msoShapeRoundedRectangle
    .Shape.TextFrame.Characters.Font.Name = "Arial"
    .Shape.TextFrame.Characters.Font.Size = 12
    .Shape.TextFrame.Characters.Font.ColorIndex = 2
    .Shape.Line.ForeColor.RGB = RGB(0, 0, 0)
    .Shape.Line.BackColor.RGB = RGB(255, 255, 255)
    .Shape.Fill.Visible = msoTrue
    .Shape.TextFrame.Characters.Font.Bold = True
    .Shape.Fill.BackColor.RGB = RGB(58, 82, 184)

    ' This fills background color of the Note and sets the transarancey to 0.04
    .Shape.Fill.ForeColor.RGB = RGB(85, 85, 110)
    .Shape.Fill.Transparency = 0.04

    'This Sets the With & Height of each Note Comment Hotkey
    MyComments.Shape.Width = 200
    MyComments.Shape.Height = 40

    CommentCount = CommentCount + 1

    ' this clears the text from all of the Notes
    .Shape.TextFrame.Characters.Text = ""

    'This Adds Text to all the Notes
    '.Text Text:=.Text & "Add Note here!"

    End With
    Next 'comment


    If CommentCount > 0 Then
    'MsgBox ("A total of " & CommentCount & " comments in worksheet '" & MySheet.Name & "' of workbook '" & MyWorkbook.Name & "'" & Chr(13) & "were repositioned and resized.")

    MsgBox ("A Total Of " & CommentCount & "" & "Were change")

    fixed = True
    End If



    If fixed = False Then
    MsgBox ("No comments were detected.")
    End If

    On Error GoTo 0

    Exit Sub
    End Sub
    Last edited by iresolver; 11-01-2022 at 07:44 AM.

  8. #8
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: Add Text to all Existing Notes "Formerly known as Comments" in Merged Cells using VBA

    Try this

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    10-21-2022
    Location
    us
    MS-Off Ver
    2017
    Posts
    7

    Re: Add Text to all Existing Notes "Formerly known as Comments" in Merged Cells using VBA

    thank you I will try it

  10. #10
    Registered User
    Join Date
    10-21-2022
    Location
    us
    MS-Off Ver
    2017
    Posts
    7

    Re: Add Text to all Existing Notes "Formerly known as Comments" in Merged Cells using VBA

    I ran your code but I got an error
    error.jpg
    do you know what is wrong?
    do I need to define something in a Dim?
    Last edited by iresolver; 11-01-2022 at 10:48 AM.

  11. #11
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: Add Text to all Existing Notes "Formerly known as Comments" in Merged Cells using VBA

    Try

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    10-21-2022
    Location
    us
    MS-Off Ver
    2017
    Posts
    7

    Re: Add Text to all Existing Notes "Formerly known as Comments" in Merged Cells using VBA

    that worked great!!! thank you so much I have been working on this for days now
    is there a rating system on this forum so I can give you a 10 out of 10 Stars

    thanks again ByteMarks your the best!!!

    I would love to give back to the forum for helping me
    does the forum allow us to upload an Excel File to share with others?
    if not I could host it in my Gdrive or something.
    Last edited by iresolver; 11-01-2022 at 11:48 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 01-24-2020, 12:10 PM
  2. [SOLVED] Code to allow "Wrap Text" for merged cells.
    By moosetales in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-16-2014, 11:39 AM
  3. [SOLVED] Code that copies row of data to another sheet based on text "Complete"/"Delete"
    By Dremzy in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 04-20-2014, 05:51 PM
  4. Replies: 2
    Last Post: 04-20-2014, 11:18 AM
  5. [SOLVED] Merged cells autofit and "-"/"+" is first character
    By Linky in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-21-2013, 11:27 AM
  6. Merged cells text > 255 chars causes "#" to be displayed
    By NickHK in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-24-2005, 05:05 AM
  7. [SOLVED] "Clean Me" Macro is giving "#VALUE!" error in the Notes field.
    By Ryan Watkins in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-10-2005, 08:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1