Keyword Identification and Changes

kapriano

New Member
Joined
Nov 6, 2017
Messages
2
hi

4c7b-Untitled-picture.png



I'm doing my job using the code below
But In fact, the words (keywords) I want to delete are in the column "c"

I mean the keyword is not just a word
I have a lot of words in the column that is added to them daily.
Is there a friend who corrects my code according to the image.

thanks


Sub Demo()
Dim dataRng As Range
Dim foundCell As Range
Dim ary() As String
On Error Resume Next
' remove empty cells
ActiveSheet.UsedRange.SpecialCells(xlCellTypeBlanks).Delete Shift:=xlUp
' group cells by "t.me/canxl/" and add name for each group
Set dataRng = ActiveSheet.UsedRange 'Range("A1:A19")
With dataRng
Set c = .Find("t.me/canxl/", LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
Set c = .FindNext(c)
ReDim Preserve ary(i)
ary(i) = c.Row
i = i + 1
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
First = LBound(ary)
Last = UBound(ary)
For i = First To Last - 1
For j = i + 1 To Last
If ary(i) - ary(j) > 0 Then
Temp = ary(j)
ary(j) = ary(i)
ary(i) = Temp
End If
Next j
Next i
Dim xName As Name
For Each xName In Application.ActiveWorkbook.Names
xName.Delete
Next
For i = 0 To UBound(ary) - 1
ActiveWorkbook.Names.Add Name:="Group" & i + 1, RefersTo:=Range(Range("A" & ary(i)), Range("A" & ary(i + 1) - 1))
Next
ActiveWorkbook.Names.Add Name:="Group" & UBound(ary) + 1, RefersTo:=Range(Range("A" & ary(UBound(ary))), dataRng.End(xlDown))
' search which group contains keyword and delete the named range
With dataRng
Set c = .Find("Keyword", LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
Set c = .FindNext(c)
For Each xName In Application.ActiveWorkbook.Names
If Not Intersect(c, Range(xName)) Is Nothing Then
If Rng Is Nothing Then
Set Rng = Range(xName)
Else
Set Rng = bigRange
End If
Set bigRange = Application.Union(Range(xName), Rng)
xName.Delete
End If
Next
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
bigRange.Delete
If Error.Count > 0 Then
Error.Clear
End If
End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Please use Excel Jeanie (or equivalent, see link in my sig) to post a portion of your worksheet and repost your code using code tags (see link in my sig) so the indenting is preserved.
 
Upvote 0
If you have time, please provide the solution you used so it can help others (and remember [CODE] (your code here) [/CODE] tags are everyone's friend).
 
Upvote 0

Forum statistics

Threads
1,216,068
Messages
6,128,592
Members
449,460
Latest member
jgharbawi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top