Help choosing cells with word within a word

sweetness34

Board Regular
Joined
Jun 23, 2011
Messages
70
Hi
I need some help with code to distinguish a range of cells that have a specific word. The problem is that word is within another word. For example I have a variation of the words "SandBox", "Box", and "Wood" all in one column. I need to find the cells that have the word "Box" and not "SandBox". Right now the code I have wont exclude "SandBox". This is what I have:

Code:
Dim x As String
Dim y As String
Dim z As String
Cells.Find(What:="Box", After:=Range("A1"), SearchDirection:=xlNext).Select
x = Selection.Offset(0, 4).Address
Cells.Find(What:="Box", After:=Range("A1"), SearchDirection:=xlPrevious).Select
y = Selection.Offset(0, 4).Address
z = Selection.Offset(1, 5).Address
ActiveWorkbook.Worksheets("Sheet1").Range(z).Select
Selection.Value = Application.WorksheetFunction.Sum(Range(x, y))

How can I modify this to only find "Box".
Thanks
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
If that's all that's in the cell, use the LookAt argument (LookAt:=xlWhole)
 
Upvote 0
Hi,

You can try something like:

Code:
Dim CurrentCell As Range
Dim x As String
Dim y As String
Dim z As String

CountBox = WorksheetFunction.CountIf(Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row), "Box")

Set CurrentCell = Range("A1")
For i = 1 To CountBox
    Set CurrentCell = Cells.Find(What:="Box", After:=CurrentCell, SearchDirection:=xlNext, MatchCase:=True)
    
    x = CurrentCell.Offset(0, 4).Address
    y = CurrentCell.Offset(0, 4).Address
    z = CurrentCell.Offset(1, 5).Address
Next

Regards
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,881
Members
452,948
Latest member
Dupuhini

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