Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Finding text or part of a text inside the value cell

Hi Focus,

I am trying to compare 2 values in different cell in separeted
workbooks, but the value of cell are different. So I need to use some
"substring" funcition to compare a part of value inside the cell with
another cell. For example:
Cell1 = ZONE 101
CellX (in other workbook) = STOP XXXX ZONE 101 YYYYY

The part of text is the same, so I need to find cell1 and compare to
cellX and when I find this part of text I need do copy 2 other cell in
2 other places.

Can someone help me to do this in macros VBA?

Rgrds,
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Finding text or part of a text inside the value cell

Based on your Subject line, I'm guessing you are having trouble with the
"find" part and not the "copy" part. VBA has an InStr function which will
return the starting character position of a substring within a larger string
of text... if the substring is not contained within the larger string of
text, the function returns zero... so, you can use that to test. The InStr
function has an odd syntax in that it has an optional **first** argument. If
you simply want an exact match (case sensitive) search starting at the
beginning of the larger text string, you only need two arguments...

Position = InStr(StringOfText, SubString)

However, if you want to do a case insensitive search, you must specify the
optional first argument (the starting position within the larger text string
to begin looking) in order to be able to specify the optional fourth
argument (where you can specify case sensitivity)...

Position = InStr(StartSearchAt, StringOfText, SubString, Casing)

Look InStr up in the help files for complete details. Anyway, for your
purposes, you will want something like this...

If InStr(CellXvalue, Cell1value) 0 Then
' The text in CellX is inside the text in Cell1
' so put your code here
End If

The above is a case sensitive search; if you want a case insensitive search,
then you will want something like this...

If InStr(1, CellXvalue, Cell1value, vbTextCompare) 0 Then
' The text in CellX is inside the text in Cell1
' so put your code here
End If

Rick



wrote in message
...
Hi Focus,

I am trying to compare 2 values in different cell in separeted
workbooks, but the value of cell are different. So I need to use some
"substring" funcition to compare a part of value inside the cell with
another cell. For example:
Cell1 = ZONE 101
CellX (in other workbook) = STOP XXXX ZONE 101 YYYYY

The part of text is the same, so I need to find cell1 and compare to
cellX and when I find this part of text I need do copy 2 other cell in
2 other places.

Can someone help me to do this in macros VBA?

Rgrds,


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
How to embed large number of variables in text inside a text box? Riva Chase Excel Discussion (Misc queries) 0 October 30th 07 01:42 AM
I NEED TO CAPITIALIZE MY TEXT INSIDE THE CELL...HOW? Capitalization Excel Discussion (Misc queries) 5 May 30th 07 06:01 AM
find text in cell and replace it with part of the text in that ce. jules Excel Discussion (Misc queries) 3 May 3rd 07 10:18 AM
Finding text in a cell and returning a value based on that text [email protected] Excel Discussion (Misc queries) 5 January 10th 07 06:01 PM
Finding specific text in string - Part II Hardip Excel Worksheet Functions 1 April 8th 06 02:20 PM


All times are GMT +1. The time now is 05:42 AM.

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

About Us

"It's about Microsoft Excel"