+ Reply to Thread
Results 1 to 5 of 5

Adding a Comment Box

Hybrid View

  1. #1
    Registered User
    Join Date
    03-02-2015
    Location
    ridgecrest, ca
    MS-Off Ver
    2010
    Posts
    54

    Adding a Comment Box

    I am just getting back into using VBA to create unique functions for MS Excel. I am trying to create code that will search the entire worksheet that is active for the phrase "Vacancy". For each time "Vacancy" is found the code will insert a comment box. The comment box will then search if after Vacancy a number is entered (so for the example the ActiveCell being searched would contain either "Vacancy 74" or text not containing "Vacancy". For the cells not containing "Vacancy" I do not want anything to be processed on them.)
    If the "Vacancy (and a #)" is found a comment box will be inserted on that active cell- the Comment box will take the number search another worksheet (FY_15_Hiring) for the number in column r. If that number is found in column r, then text from(FY_15_Hiring) column d, row (=to the row where the number was found in column r).

    I know this is a lot but I am getting stumped on just the search and insert portion. Please help.

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Adding a Comment Box

    Sub clpickett3()
    
    Set ws1 = ActiveSheet
    Set ws2 = Worksheets("FY_15_Hiring")
    
    Set c = ws1.Cells.Find("Vacancy", lookat:=xlPart)
    If Not c Is Nothing Then
        FirstAdd = c.Address
        Do
        If c.Comment Is Nothing Then c.AddComment
        c.Comment.Visible = False
        Set d = ws2.Range("R:R").Find(Split(c.Value, "Vacancy ")(1))
        If Not d Is Nothing Then
            c.Comment.Text Text:="from (FY_15_Hiring)" & Chr(10) & "column r, row " & d.Row
        End If
        Set c = ws1.Cells.Find("Vacancy", lookat:=xlPart, after:=c)
        Loop While Not c Is Nothing And c.Address <> FirstAdd
    End If
    
    End Sub
    Last edited by walruseggman; 03-02-2015 at 04:18 PM. Reason: Added check to only add comment if one doesn't already exist in that cell

  3. #3
    Registered User
    Join Date
    03-02-2015
    Location
    ridgecrest, ca
    MS-Off Ver
    2010
    Posts
    54

    Re: Adding a Comment Box

    Sub clpickett3()

    Set ws1 = ActiveSheet
    Set ws2 = Worksheets("Sheet3")

    Set c = ws1.Cells.Find("Vacancy", lookat:=xlPart)
    If Not c Is Nothing Then
    FirstAdd = c.Address
    Do
    If c.Comment Is Nothing Then c.AddComment
    c.Comment.Visible = False
    Set d = ws2.Range("R:R").Find(Split(c.Value, "Vacancy ")(1))
    If Not d Is Nothing Then
    c.Comment.Text Text:="from (FY_15_Staffing)" & Chr(10) & "column r, row " & b.Row
    End If
    Set c = ws1.Cells.Find("Vacancy", lookat:=xlPart, after:=c)
    Loop While Not c Is Nothing And c.Address <> FirstAdd
    End If

    End Sub

    I am getting a runtime error stating subscript out of ranger

  4. #4
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Adding a Comment Box

    Edit: Also just noticed you changed d.Row to b.Row that's probably your error.

    I thought you wanted to search FY_15_Hiring?

    ws1 is whatever sheet has the "Vacancy" s on it
    ws2 is whatever sheet you want to search for the matching number

    If that doesn't help, please post your workbook or an example workbook that replicates the error.
    Last edited by walruseggman; 03-02-2015 at 06:20 PM.

  5. #5
    Registered User
    Join Date
    03-02-2015
    Location
    ridgecrest, ca
    MS-Off Ver
    2010
    Posts
    54

    Re: Adding a Comment Box

    They changed the name of the 1 worksheet to FY_15_Staffing. Column R is still being searched for the number that is after the word vacancy on WS1. Column B houses the information they wish to be displayed correlating to the row found in column r.ws1.jpgws2.jpg
    Attached Images Attached Images

+ 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. Disable Delete Comment, Edit Comment, Show/Hide Comment
    By Shanthan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-17-2013, 06:12 AM
  2. [SOLVED] Adding a variable value to a comment?
    By Tom in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-10-2006, 07:30 PM
  3. Adding a comment to a cell
    By mancitmis in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 11-03-2005, 04:52 AM
  4. adding comment to cell
    By mancitmis in forum Excel General
    Replies: 1
    Last Post: 11-02-2005, 11:15 AM
  5. Adding a comment to a cell in VBA?!
    By Maury Markowitz in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-27-2005, 12:05 PM

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