Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Searching a cell for certain contents

I would like to check to see if a cell contains a certain string within the
whole cell. For example, if column B has a lot of data, and one of the
entries is "The cat in the hat" I would like a macro to search column B for
the word hat. I don't care what happens when it finds it at the moment, as I
believe i can establish that myself, I just need a command to search within a
cell for a certain word. I've tried using the InStr command a bit, but to no
avail!

Any help would be much appreciated! Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default Searching a cell for certain contents

Columns("B:B").Select
Selection.Find(What:="hat", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate



"Derek Johansen" wrote:

I would like to check to see if a cell contains a certain string within the
whole cell. For example, if column B has a lot of data, and one of the
entries is "The cat in the hat" I would like a macro to search column B for
the word hat. I don't care what happens when it finds it at the moment, as I
believe i can establish that myself, I just need a command to search within a
cell for a certain word. I've tried using the InStr command a bit, but to no
avail!

Any help would be much appreciated! Thanks!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Searching a cell for certain contents

Okay, I lied, I can't get it to do what I want with the data. It should be
fairly simple, all I want to do is edit column J according to what is in
Column B. If Column B contains "BCI" i need to change column J to "I-Joist."
This should be an easy addition I would think, but I've only been working
with VBA for a couple days now, so I'm not very proficient...

"dmoney" wrote:

Columns("B:B").Select
Selection.Find(What:="hat", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate



"Derek Johansen" wrote:

I would like to check to see if a cell contains a certain string within the
whole cell. For example, if column B has a lot of data, and one of the
entries is "The cat in the hat" I would like a macro to search column B for
the word hat. I don't care what happens when it finds it at the moment, as I
believe i can establish that myself, I just need a command to search within a
cell for a certain word. I've tried using the InStr command a bit, but to no
avail!

Any help would be much appreciated! Thanks!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default Searching a cell for certain contents

ActiveCell.Offset(0, 8).Value = "enjoy"

"Derek Johansen" wrote:

I would like to check to see if a cell contains a certain string within the
whole cell. For example, if column B has a lot of data, and one of the
entries is "The cat in the hat" I would like a macro to search column B for
the word hat. I don't care what happens when it finds it at the moment, as I
believe i can establish that myself, I just need a command to search within a
cell for a certain word. I've tried using the InStr command a bit, but to no
avail!

Any help would be much appreciated! Thanks!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Searching a cell for certain contents

I will test this when I get back to the office and let you know how it goes:
i appreciate the timely responses, thank you!

"dmoney" wrote:

ActiveCell.Offset(0, 8).Value = "enjoy"

"Derek Johansen" wrote:

I would like to check to see if a cell contains a certain string within the
whole cell. For example, if column B has a lot of data, and one of the
entries is "The cat in the hat" I would like a macro to search column B for
the word hat. I don't care what happens when it finds it at the moment, as I
believe i can establish that myself, I just need a command to search within a
cell for a certain word. I've tried using the InStr command a bit, but to no
avail!

Any help would be much appreciated! Thanks!



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Searching a cell for certain contents

Mr. Money,
I am getting a run-time error with this code:

Selection.Find(What:="hat", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

It says "Object variable or With block variable not set."
Any suggestions?


"dmoney" wrote:

ActiveCell.Offset(0, 8).Value = "enjoy"

"Derek Johansen" wrote:

I would like to check to see if a cell contains a certain string within the
whole cell. For example, if column B has a lot of data, and one of the
entries is "The cat in the hat" I would like a macro to search column B for
the word hat. I don't care what happens when it finds it at the moment, as I
believe i can establish that myself, I just need a command to search within a
cell for a certain word. I've tried using the InStr command a bit, but to no
avail!

Any help would be much appreciated! Thanks!

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default Searching a cell for certain contents

u need to make sure that something is selected before running this code

for example
Columns("B:B").Select


"Derek Johansen" wrote:

Mr. Money,
I am getting a run-time error with this code:

Selection.Find(What:="hat", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

It says "Object variable or With block variable not set."
Any suggestions?


"dmoney" wrote:

ActiveCell.Offset(0, 8).Value = "enjoy"

"Derek Johansen" wrote:

I would like to check to see if a cell contains a certain string within the
whole cell. For example, if column B has a lot of data, and one of the
entries is "The cat in the hat" I would like a macro to search column B for
the word hat. I don't care what happens when it finds it at the moment, as I
believe i can establish that myself, I just need a command to search within a
cell for a certain word. I've tried using the InStr command a bit, but to no
avail!

Any help would be much appreciated! Thanks!

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Searching a cell for certain contents

Okay, I have established that this run-time error only occurs when the string
does not occur in any cells. How do I avoid this, because I want to run the
macro on every worksheet i import, but it can't run-time error just because
there is no "BCI" found in column B

"dmoney" wrote:

u need to make sure that something is selected before running this code

for example
Columns("B:B").Select


"Derek Johansen" wrote:

Mr. Money,
I am getting a run-time error with this code:

Selection.Find(What:="hat", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

It says "Object variable or With block variable not set."
Any suggestions?


"dmoney" wrote:

ActiveCell.Offset(0, 8).Value = "enjoy"

"Derek Johansen" wrote:

I would like to check to see if a cell contains a certain string within the
whole cell. For example, if column B has a lot of data, and one of the
entries is "The cat in the hat" I would like a macro to search column B for
the word hat. I don't care what happens when it finds it at the moment, as I
believe i can establish that myself, I just need a command to search within a
cell for a certain word. I've tried using the InStr command a bit, but to no
avail!

Any help would be much appreciated! Thanks!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Searching alfanumaric cell contents and returning with a numaric v ksean Excel Discussion (Misc queries) 21 October 29th 09 04:55 PM
Searching a cells contents? SteW Excel Worksheet Functions 2 August 21st 07 11:48 AM
Searching in another workbook for a string and returning with the contents of the cell next to it. [email protected] Excel Worksheet Functions 1 January 12th 07 07:50 PM
Searching through the contents of a Folder of text files jase[_2_] Excel Programming 1 January 6th 06 03:48 PM
Data searching based on cell contents using VBa Craig Easton Excel Programming 1 November 25th 04 05:19 AM


All times are GMT +1. The time now is 12:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"