Results 1 to 11 of 11

Sub to check for Hashtags in comments column using list in different sheet

Threaded View

  1. #1
    Registered User
    Join Date
    11-24-2016
    Location
    Melbourne
    MS-Off Ver
    2016
    Posts
    6

    Sub to check for Hashtags in comments column using list in different sheet

    Hi,

    I'm new to VBA so hoping to get some help.

    I found a sub to extract hashtags out of a cell (column J, in sheet 2) and place into another cell (column S, in sheet 2). The code references a list of hashtags in another tab within the workbook (column A, in sheet 3).

    The sub originally referenced the same sheet when looking at the list of Hashtags but I want it to to look at another sheet. I thought I needed to declare and set the two sheets (Sht2 for "Sheet2" and Sht3 for "Sheet3") and made adjustments to the code to reference these sheets and cells. It seems to compile but nothing is appearing in the column when I attempt to run the macro.

    Would greatly appreciate someone pointing out exactly what I'm doing wrong and a possible solution, thanks.

    Here's my code...

    Sub Tags()
    
        Dim wrdLRow As Integer
        Dim wrdLp As Integer
        Dim CommentLrow As Integer
        Dim CommentLp As Integer
        Dim fndWord As Integer
        
    '   Declare sheets that we will be referencing
        Dim Sht2 As Sheets
        Dim Sht3 As Sheets
    
        On Error Resume Next 'Suppress Errors... for when we don't find a match
        
    '   Define worksheets that contain data
    '   ignore Set Sht = Sheets("Sheet1")
        Set Sht2 = Sheets("Sheet2")
        Set Sht3 = Sheets("Sheet3")
        
        'Get last row for hashtags based on column A in sheet3 (aka Hastag Lookup)
        wrdLRow = Sht3("Sheet3").Cells(Rows.Count, "A").End(xlUp).Row
        
        'Get last row for posts based on column J in sheet2 (aka All Merged Data)
        CommentLrow = Sht2("Sheet2").Cells(Rows.Count, "J").End(xlUp).Row
        
        'Loop through lists and find matches....
        For CommentLp = 2 To CommentLrow
        
            For wrdLp = 2 To wrdLRow
    
                'Look for hashtags...
                fndWord = Application.WorksheetFunction.Search(Sht3("Sheet3").Cells(wrdLp, "A"), Sht2("Sheet2").Cells(CommentLp, "J"))
                
                'If we found the hashtag....then
                If fndWord > 0 Then
                    Sht2("Sheet2").Cells(CommentLp, "S") = Sht2("Sheet2").Cells(CommentLp, "S") & "; " & Sht2("Sheet2").Cells(wrdLp, "S")
                    fndWord = 0 'Reset Variable for next loop
                End If
                
            Next wrdLp
            
            Sht2("Sheet2").Cells(CommentLp, "S") = Mid(Sht2("Sheet2").Cells(CommentLp, "S"), 3, Len(Sht2("Sheet2").Cells(CommentLp, "S")) - 2)
    
        Next CommentLp
    
    End Sub
    Moderator's note: Thank you for your first post in nearly 5 years! Please take the time to review our rules. There aren't many, and they are all important. Rule #2 requires code tags. I have added them for you this time because it's your first post. --6StringJazzer
    Last edited by 6StringJazzer; 06-16-2021 at 08:43 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Extracting hashtags and mentions from textual column
    By alexM123 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-23-2020, 01:37 PM
  2. [SOLVED] Insertion of Random Hashtags in each row of a column
    By WhatsGig in forum Excel General
    Replies: 4
    Last Post: 08-16-2017, 09:09 AM
  3. Macro to insert cell comments from a list in another sheet
    By Bambina in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-02-2015, 09:02 AM
  4. [SOLVED] check column headers against sheet names if sheet not exist create it
    By AkaTrouble in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-13-2015, 05:59 PM
  5. Replies: 0
    Last Post: 05-20-2014, 03:23 AM
  6. Transfer comments from Sheet 1 to Sheet 2 as list
    By Welshandproud1 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-16-2014, 06:52 AM
  7. Add comments to cells using VBA (comments from list)
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-15-2010, 12:11 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