jholly1984
New Member
- Joined
- Sep 29, 2020
- Messages
- 15
- Office Version
- 2016
- 2010
- Platform
- Windows
Hi there, and thank you in advance for helping me with this!
I have a previous macro that I received help with a few years ago which has been serving me well: Original Solution's Post
However, I'm running into trouble with the accuracy. Essentially, if my list of modifier words to be found has short words that can be partial matches to other words, it returns the longer words as though they match the words being found in the cells. For example, if I use the word "car" or "id" or "ai", expecting only cells that contain those words.
When the modifier is "car" I only expect it to return cells that have "car" (i.e. "car wash", "race car", "driving my car on a rainy day" - which it does!) but it also returns cells that contain longer variations (i.e. "cardstock", "carson", "take the streetcar to the second stop").
I've tried using spaces in front/behind the words, but then I don't capture instances where the cell starts or ends with the modifier word in question. I've tried adding a single or double quote in front and behind each word in the list, but that doesn't seem to work either.
Any help you can provide would be HUGELY appreciated!
I have a previous macro that I received help with a few years ago which has been serving me well: Original Solution's Post
However, I'm running into trouble with the accuracy. Essentially, if my list of modifier words to be found has short words that can be partial matches to other words, it returns the longer words as though they match the words being found in the cells. For example, if I use the word "car" or "id" or "ai", expecting only cells that contain those words.
VBA Code:
Sub Maybe()
Dim c As Range, i As Long, sh1 As Worksheet
Application.ScreenUpdating = False
Set sh1 = Worksheets("data") '<-----Sheet with all the data. Change as required
Set sh2 = Worksheets("modifiers") '<-----Sheet with all the modifiers. Change as required
For Each c In sh2.Range("a2:a114")
If Not [ISREF(c.Value!A1)] Then Sheets.Add(, Sheets(Sheets.Count)).Name = c.Value
For i = 2 To sh1.Cells(Rows.Count, 4).End(xlUp).Row
If InStr(sh1.Cells(i, 4), c) > 0 Then
With Sheets(c.Value)
.Cells(1, 1).Resize(, 9).Value = sh1.Cells(1, 1).Resize(, 9).Value
.Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(, 9).Value = sh1.Cells(i, 1).Resize(, 9).Value
End With
End If
Next i
Next c
Sheets("data").Select '<-----Sheet with all the data. Change as required
Application.ScreenUpdating = True
End Sub
When the modifier is "car" I only expect it to return cells that have "car" (i.e. "car wash", "race car", "driving my car on a rainy day" - which it does!) but it also returns cells that contain longer variations (i.e. "cardstock", "carson", "take the streetcar to the second stop").
I've tried using spaces in front/behind the words, but then I don't capture instances where the cell starts or ends with the modifier word in question. I've tried adding a single or double quote in front and behind each word in the list, but that doesn't seem to work either.
Any help you can provide would be HUGELY appreciated!