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
Bookmarks