#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Search Code

Hi All,

I have the following code to search all the sheets in my
workbook for a give text in my userform1 textbox1

How can I get the code to search last charecters only
based on my textbox1.text.

i want get the code modified to get something like this.

if y=len(textbox1.text)

I want to search SStr in right(B:B ,y)

How I could modify my code to get this?


Sub SearchTkt()
Application.ScreenUpdating = False
sStr = textbox1.Text
For Each sh In ThisWorkbook.Worksheets
If sStr < "" Then
Set rng = Nothing
Set rng = sh.Range("B:B").Find(What:=sStr, _
After:=sh.Range("B1"), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
End If

TIA
Soniya
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Search Code

..find is pretty neat.

If it's the rightmost characters you're looking for, you can use:

Set rng = sh.Range("B:B").Find(What:="*" & sStr, _
After:=sh.Range("B1"), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

Now you're looking for "*" & sStr in xlWhole.

This means you want it to end with those characters.

You can do the opposite if you're looking for leading characters, too. (sStr &
"*" and xlWhole).

Soniya wrote:

Hi All,

I have the following code to search all the sheets in my
workbook for a give text in my userform1 textbox1

How can I get the code to search last charecters only
based on my textbox1.text.

i want get the code modified to get something like this.

if y=len(textbox1.text)

I want to search SStr in right(B:B ,y)

How I could modify my code to get this?

Sub SearchTkt()
Application.ScreenUpdating = False
sStr = textbox1.Text
For Each sh In ThisWorkbook.Worksheets
If sStr < "" Then
Set rng = Nothing
Set rng = sh.Range("B:B").Find(What:=sStr, _
After:=sh.Range("B1"), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
End If

TIA
Soniya


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Search Code

Soniya;

To convert text to a number use the VAL function.
dim intI as integer

intI = Val( string)

So using your textbox text looks like this.
intI = VAl( textbox1.txt)

To search for one string within another use InStr( strToSearch,
strToSearchFor, intStart)

dim intRow as integer

for intRow = 1 to 99
if InStr( Right( activeWorkheet.Cell(intRow,intColumn).Value, intI), SStr,
1) then
'Do what you wanted to do.
endif
next intRow

You may use a Do While loop using isEmpty to stop when you reach an empty row.

You might want to check the text going into the textbox to make sure you
only enter
numbers. This is done by putting code into the textBox1_Keypress() and
textBox1_OnChange() events.

Hope this helps. I didn't code and test it.


"Soniya" wrote:

Hi All,

I have the following code to search all the sheets in my
workbook for a give text in my userform1 textbox1

How can I get the code to search last charecters only
based on my textbox1.text.

i want get the code modified to get something like this.

if y=len(textbox1.text)

I want to search SStr in right(B:B ,y)

How I could modify my code to get this?


Sub SearchTkt()
Application.ScreenUpdating = False
sStr = textbox1.Text
For Each sh In ThisWorkbook.Worksheets
If sStr < "" Then
Set rng = Nothing
Set rng = sh.Range("B:B").Find(What:=sStr, _
After:=sh.Range("B1"), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
End If

TIA
Soniya

  #4   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Search Code

Thanks Dave,

Yur code helped me..!


-----Original Message-----
..find is pretty neat.

If it's the rightmost characters you're looking for, you

can use:

Set rng = sh.Range("B:B").Find(What:="*" & sStr, _
After:=sh.Range("B1"), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

Now you're looking for "*" & sStr in xlWhole.

This means you want it to end with those characters.

You can do the opposite if you're looking for leading

characters, too. (sStr &
"*" and xlWhole).

Soniya wrote:

Hi All,

I have the following code to search all the sheets in

my
workbook for a give text in my userform1 textbox1

How can I get the code to search last charecters only
based on my textbox1.text.

i want get the code modified to get something like

this.

if y=len(textbox1.text)

I want to search SStr in right(B:B ,y)

How I could modify my code to get this?

Sub SearchTkt()
Application.ScreenUpdating = False
sStr = textbox1.Text
For Each sh In ThisWorkbook.Worksheets
If sStr < "" Then
Set rng = Nothing
Set rng = sh.Range("B:B").Find(What:=sStr, _
After:=sh.Range("B1"), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
End If

TIA
Soniya


--

Dave Peterson

.

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
VBA code for search button Dylan @ UAFC[_2_] Excel Worksheet Functions 3 November 25th 08 10:59 PM
Excel XP VBA code to search all macro code in Excel module for specific search string criteria Ed[_18_] Excel Programming 4 May 20th 04 02:08 PM
Excel XP VBA code to search all macro code in Excel module for specific search string criteria Frank Kabel Excel Programming 0 May 19th 04 08:11 PM
Search code Bourbon[_7_] Excel Programming 2 January 10th 04 06:14 PM
File Search code Abdul Salam Excel Programming 3 August 6th 03 03:44 PM


All times are GMT +1. The time now is 07:13 PM.

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"