Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Find value, perform function, search for next value

Hi, I am having trouble with writing a "find" code that will work. Here is
what I want to do:

I need to search column A for "Account Category:" and call out a macro on
that cell, then find the next instance and do the same. My worksheet is a
few thousand lines so having an automated find function will make a HUGE
difference! Part of the problem too is that the cells in question will
always begin with "Account Category:" but may differ, like one will be
"Account Category: 20512" and another might be "Account Category: 22265". I
tried recording a macro while I used the find function, but it wouldn't work
when I tried to run it.

Suggestions are greatly appreciated! Thanks in advance
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Find value, perform function, search for next value

Something like this should be close...

Sub test()
Dim rngFound As Range
Dim rngToSearch As Range
Dim strFirstAddress As String

Set rngToSearch = Sheets("Sheet1").Columns("A")
Set rngFound = rngToSearch.Find(What:="Account Category:*", _
LookAt:=xlWhole, _
LookIn:=xlValues, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Sorry... Not Found"
Else
strFirstAddress = rngFound.Address
Do
rngFound.Select
MsgBox rngFound.Value & " found at " & rngFound.Address
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until strFirstAddress = rngFound.Address
End If
End Sub
--
HTH...

Jim Thomlinson


"SLW612" wrote:

Hi, I am having trouble with writing a "find" code that will work. Here is
what I want to do:

I need to search column A for "Account Category:" and call out a macro on
that cell, then find the next instance and do the same. My worksheet is a
few thousand lines so having an automated find function will make a HUGE
difference! Part of the problem too is that the cells in question will
always begin with "Account Category:" but may differ, like one will be
"Account Category: 20512" and another might be "Account Category: 22265". I
tried recording a macro while I used the find function, but it wouldn't work
when I tried to run it.

Suggestions are greatly appreciated! Thanks in advance

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Find value, perform function, search for next value

Thanks for the quick reply, Jim ... but it's not working. I get the
"Sorry...Not Found" every time, even when I am looking right at a cell that
begins with "Account Category:". When I type "Account Category:*" into the
find dialog it has no problems finding the search term, so there must be
something I'm missing ...

Any other ideas?



"Jim Thomlinson" wrote:

Something like this should be close...

Sub test()
Dim rngFound As Range
Dim rngToSearch As Range
Dim strFirstAddress As String

Set rngToSearch = Sheets("Sheet1").Columns("A")
Set rngFound = rngToSearch.Find(What:="Account Category:*", _
LookAt:=xlWhole, _
LookIn:=xlValues, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Sorry... Not Found"
Else
strFirstAddress = rngFound.Address
Do
rngFound.Select
MsgBox rngFound.Value & " found at " & rngFound.Address
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until strFirstAddress = rngFound.Address
End If
End Sub
--
HTH...

Jim Thomlinson


"SLW612" wrote:

Hi, I am having trouble with writing a "find" code that will work. Here is
what I want to do:

I need to search column A for "Account Category:" and call out a macro on
that cell, then find the next instance and do the same. My worksheet is a
few thousand lines so having an automated find function will make a HUGE
difference! Part of the problem too is that the cells in question will
always begin with "Account Category:" but may differ, like one will be
"Account Category: 20512" and another might be "Account Category: 22265". I
tried recording a macro while I used the find function, but it wouldn't work
when I tried to run it.

Suggestions are greatly appreciated! Thanks in advance

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Find value, perform function, search for next value

Try

Set rngFound = rngToSearch.Find(What:="Account Category:*", _
LookAt:=xlPart, _
LookIn:=xlValues, _
MatchCase:=False)


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"SLW612" wrote in message
...
Thanks for the quick reply, Jim ... but it's not working. I get the
"Sorry...Not Found" every time, even when I am looking right at a cell
that
begins with "Account Category:". When I type "Account Category:*" into
the
find dialog it has no problems finding the search term, so there must be
something I'm missing ...

Any other ideas?



"Jim Thomlinson" wrote:

Something like this should be close...

Sub test()
Dim rngFound As Range
Dim rngToSearch As Range
Dim strFirstAddress As String

Set rngToSearch = Sheets("Sheet1").Columns("A")
Set rngFound = rngToSearch.Find(What:="Account Category:*", _
LookAt:=xlWhole, _
LookIn:=xlValues, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Sorry... Not Found"
Else
strFirstAddress = rngFound.Address
Do
rngFound.Select
MsgBox rngFound.Value & " found at " & rngFound.Address
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until strFirstAddress = rngFound.Address
End If
End Sub
--
HTH...

Jim Thomlinson


"SLW612" wrote:

Hi, I am having trouble with writing a "find" code that will work.
Here is
what I want to do:

I need to search column A for "Account Category:" and call out a macro
on
that cell, then find the next instance and do the same. My worksheet
is a
few thousand lines so having an automated find function will make a
HUGE
difference! Part of the problem too is that the cells in question will
always begin with "Account Category:" but may differ, like one will be
"Account Category: 20512" and another might be "Account Category:
22265". I
tried recording a macro while I used the find function, but it wouldn't
work
when I tried to run it.

Suggestions are greatly appreciated! Thanks in advance



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Find value, perform function, search for next value

I tried Jim's code and it worked fine. I copied his code from the posting,
set up a test shee with Account Category: 123, 234, 345 in three different
cells of column A and it found all three. Check your spelling, and make
sure that if you did not copy Jim's code, that your typed it exactly as he
wrote it, including the asterisk in the What:= .

"SLW612" wrote:

Thanks for the quick reply, Jim ... but it's not working. I get the
"Sorry...Not Found" every time, even when I am looking right at a cell that
begins with "Account Category:". When I type "Account Category:*" into the
find dialog it has no problems finding the search term, so there must be
something I'm missing ...

Any other ideas?



"Jim Thomlinson" wrote:

Something like this should be close...

Sub test()
Dim rngFound As Range
Dim rngToSearch As Range
Dim strFirstAddress As String

Set rngToSearch = Sheets("Sheet1").Columns("A")
Set rngFound = rngToSearch.Find(What:="Account Category:*", _
LookAt:=xlWhole, _
LookIn:=xlValues, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Sorry... Not Found"
Else
strFirstAddress = rngFound.Address
Do
rngFound.Select
MsgBox rngFound.Value & " found at " & rngFound.Address
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until strFirstAddress = rngFound.Address
End If
End Sub
--
HTH...

Jim Thomlinson


"SLW612" wrote:

Hi, I am having trouble with writing a "find" code that will work. Here is
what I want to do:

I need to search column A for "Account Category:" and call out a macro on
that cell, then find the next instance and do the same. My worksheet is a
few thousand lines so having an automated find function will make a HUGE
difference! Part of the problem too is that the cells in question will
always begin with "Account Category:" but may differ, like one will be
"Account Category: 20512" and another might be "Account Category: 22265". I
tried recording a macro while I used the find function, but it wouldn't work
when I tried to run it.

Suggestions are greatly appreciated! Thanks in advance



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Find value, perform function, search for next value

Ah, I found the problem. I should have specified that column A was merged
through to col. J - when I changed the range from "A" to "A:J" it found it
with no problems.

Thanks again!


"JLGWhiz" wrote:

I tried Jim's code and it worked fine. I copied his code from the posting,
set up a test shee with Account Category: 123, 234, 345 in three different
cells of column A and it found all three. Check your spelling, and make
sure that if you did not copy Jim's code, that your typed it exactly as he
wrote it, including the asterisk in the What:= .

"SLW612" wrote:

Thanks for the quick reply, Jim ... but it's not working. I get the
"Sorry...Not Found" every time, even when I am looking right at a cell that
begins with "Account Category:". When I type "Account Category:*" into the
find dialog it has no problems finding the search term, so there must be
something I'm missing ...

Any other ideas?



"Jim Thomlinson" wrote:

Something like this should be close...

Sub test()
Dim rngFound As Range
Dim rngToSearch As Range
Dim strFirstAddress As String

Set rngToSearch = Sheets("Sheet1").Columns("A")
Set rngFound = rngToSearch.Find(What:="Account Category:*", _
LookAt:=xlWhole, _
LookIn:=xlValues, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Sorry... Not Found"
Else
strFirstAddress = rngFound.Address
Do
rngFound.Select
MsgBox rngFound.Value & " found at " & rngFound.Address
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until strFirstAddress = rngFound.Address
End If
End Sub
--
HTH...

Jim Thomlinson


"SLW612" wrote:

Hi, I am having trouble with writing a "find" code that will work. Here is
what I want to do:

I need to search column A for "Account Category:" and call out a macro on
that cell, then find the next instance and do the same. My worksheet is a
few thousand lines so having an automated find function will make a HUGE
difference! Part of the problem too is that the cells in question will
always begin with "Account Category:" but may differ, like one will be
"Account Category: 20512" and another might be "Account Category: 22265". I
tried recording a macro while I used the find function, but it wouldn't work
when I tried to run it.

Suggestions are greatly appreciated! Thanks in advance

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
Search / Find Function Harry C. Excel Worksheet Functions 6 June 16th 09 05:40 PM
Find / Search Function Andrew Excel Discussion (Misc queries) 1 October 12th 08 08:25 PM
why is there no excel11.xlb file when I perform a search? chuckdtke Excel Discussion (Misc queries) 3 December 14th 07 10:45 PM
perform 1 function, stop, perform different function nastech Excel Discussion (Misc queries) 0 August 22nd 06 12:21 PM
Find & Search Function drvortex Excel Worksheet Functions 6 June 16th 06 08:34 PM


All times are GMT +1. The time now is 01:13 AM.

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"