Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default "find" finesse needed

:) i have my workbooks & worksheets straight now, thanks to jim!

i need to find a variable in a range, but without selecting the range,
i can't tell it to look after:activecell. i searched the newsgroup &
discovered using cells.count but it's not working. what am i doing
wrong (again)?

xxxxxxxxxxx
Sub ActualCopy()

LastRangeRow = wsMyInvoiceSheet.Cells(20000, 7).End(xlUp).Row

Set r = Range("g1:g" & LastRangeRow)

'find the program name in wsMyInvoiceSheet

r.Cells.Find(What:=myProgram, After:=r(r.Cells.Count),
LookIn:=xlValues, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False).Activate

<snip
End Sub
xxxxxxxxxxxxxxx

i'm getting my favorite run-time 91 error.

if i change the range to
Set r = wsMyInvoiceSheet.Range("g1:g" & LastRangeRow)
it bombs on the same "find" line, but with a different error message:
run time error 1004 - activate method of range class failed.

suggestions gratefully accepted! thanks
susan

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default "find" finesse needed

oh.... one of the posts when i was searching said that "after" was not
optional.
so i will try taking it out. & the reason i narrowed the search area
instead of just the column was because i thought perhaps that was where
the problem was; so now i know i can put that back.

in THIS specific macro, it will always find what it is looking for, but
i didn't know how to go about an "if-it-doesn't-find-it" issue, so
thank you for explaining that, also.

see, i'm not looking to see IF it is there, what i really want to know
is where in the 300+-row spreadsheet the value IS. thinking out loud,
in that case i can probably use the rngFound.row address............
:D
many thanks for your help!
susan


Jim Thomlinson wrote:
When using find you don't need to be quite so explicit in the range you are
searching. Also note that After is an optional argument. The issue that I do
see is that the code will bomb out if you don't actually find what you are
looking for. Give this a whirl...

Sub ActualCopy()
Dim rngToSearch As Range
Dim rngFound As Range

Set rngToSearch = wsMyInvoiceSheet.Columns("G")

'find the program name in wsMyInvoiceSheet
Set rngFound = rngToSearch.Find(What:=myProgram, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
MatchCase:=False)

If rngFound Is Nothing Then
MsgBox "Sorry " & myProgram & " was not found."
Else
MsgBox rngFound.Address
End If
End Sub


--
HTH...

Jim Thomlinson


"Susan" wrote:

:) i have my workbooks & worksheets straight now, thanks to jim!

i need to find a variable in a range, but without selecting the range,
i can't tell it to look after:activecell. i searched the newsgroup &
discovered using cells.count but it's not working. what am i doing
wrong (again)?

xxxxxxxxxxx
Sub ActualCopy()

LastRangeRow = wsMyInvoiceSheet.Cells(20000, 7).End(xlUp).Row

Set r = Range("g1:g" & LastRangeRow)

'find the program name in wsMyInvoiceSheet

r.Cells.Find(What:=myProgram, After:=r(r.Cells.Count),
LookIn:=xlValues, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False).Activate

<snip
End Sub
xxxxxxxxxxxxxxx

i'm getting my favorite run-time 91 error.

if i change the range to
Set r = wsMyInvoiceSheet.Range("g1:g" & LastRangeRow)
it bombs on the same "find" line, but with a different error message:
run time error 1004 - activate method of range class failed.

suggestions gratefully accepted! thanks
susan



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
"Find" a wildcard as a place marker and "replace" with original va Eric Excel Discussion (Misc queries) 1 January 27th 09 06:00 PM
Find all cells NOT containing "100%" -no loop solution needed tskogstrom Excel Programming 2 November 25th 06 04:33 PM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
fomula needed to find the "new" time, for example if [email protected] Excel Discussion (Misc queries) 7 June 27th 06 12:24 AM


All times are GMT +1. The time now is 11:01 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"