Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Find method syntax

Hi All,
I'd like to understand the difference between these two syntaxes below:

a./ lastcolumn = Cells.Find(What:="*", _
After:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlValues, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
This one works!

b./ lastcolumn = Cells.Find("*", Range("A1"), xlPart,
xlValues, xlByColumns, xlPrevious, False).Column

This one does not work at the same place in the code, but gives an error
message No. 1004 saying Find property of Class range not accessible!

Regards,
Stefi

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Find method syntax

That is because in the first example you have the Find arguments out of
order, LookIn comes before LookAt in the order. By specifying the keywords
that doesn't matter, but when you don't specify them you need to be in the
correct order.

So

lastcolumn = Cells.Find("*", Range("A1"), xlValues, xlPart,
xlByColumns, xlPrevious, False).Column

should work

--
HTH

Bob Phillips

"Stefi" wrote in message
...
Hi All,
I'd like to understand the difference between these two syntaxes below:

a./ lastcolumn = Cells.Find(What:="*", _
After:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlValues, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
This one works!

b./ lastcolumn = Cells.Find("*", Range("A1"), xlPart,
xlValues, xlByColumns, xlPrevious, False).Column

This one does not work at the same place in the code, but gives an error
message No. 1004 saying Find property of Class range not accessible!

Regards,
Stefi



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Find method syntax

Thanks, Bob, how obvious the answer and how difficult to notice the
difference for an unpracticed eye.
Stefi


€˛Bob Phillips€¯ ezt Ć*rta:

That is because in the first example you have the Find arguments out of
order, LookIn comes before LookAt in the order. By specifying the keywords
that doesn't matter, but when you don't specify them you need to be in the
correct order.

So

lastcolumn = Cells.Find("*", Range("A1"), xlValues, xlPart,
xlByColumns, xlPrevious, False).Column

should work

--
HTH

Bob Phillips

"Stefi" wrote in message
...
Hi All,
I'd like to understand the difference between these two syntaxes below:

a./ lastcolumn = Cells.Find(What:="*", _
After:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlValues, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
This one works!

b./ lastcolumn = Cells.Find("*", Range("A1"), xlPart,
xlValues, xlByColumns, xlPrevious, False).Column

This one does not work at the same place in the code, but gives an error
message No. 1004 saying Find property of Class range not accessible!

Regards,
Stefi




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Find method syntax

That's why its good programming practice to use named arguments.
Sure, its a bit more typing, but it saves you from errors in
calling methods.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Stefi" wrote in message
...
Thanks, Bob, how obvious the answer and how difficult to notice
the
difference for an unpracticed eye.
Stefi


"Bob Phillips" ezt ķrta:

That is because in the first example you have the Find
arguments out of
order, LookIn comes before LookAt in the order. By specifying
the keywords
that doesn't matter, but when you don't specify them you need
to be in the
correct order.

So

lastcolumn = Cells.Find("*", Range("A1"),
xlValues, xlPart,
xlByColumns, xlPrevious, False).Column

should work

--
HTH

Bob Phillips

"Stefi" wrote in message
...
Hi All,
I'd like to understand the difference between these two
syntaxes below:

a./ lastcolumn = Cells.Find(What:="*", _
After:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlValues, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
This one works!

b./ lastcolumn = Cells.Find("*", Range("A1"),
xlPart,
xlValues, xlByColumns, xlPrevious, False).Column

This one does not work at the same place in the code, but
gives an error
message No. 1004 saying Find property of Class range not
accessible!

Regards,
Stefi






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Find method syntax

Yes, you are right, one can avoid errors by using named arguments, but I
learned what rules are to be kept to when using different syntaxes from my
own fault (and from Bob's answer of course).

Nonetheless I keep your advice in mind.
Regards,
Stefi


€˛Chip Pearson€¯ ezt Ć*rta:

That's why its good programming practice to use named arguments.
Sure, its a bit more typing, but it saves you from errors in
calling methods.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Stefi" wrote in message
...
Thanks, Bob, how obvious the answer and how difficult to notice
the
difference for an unpracticed eye.
Stefi


"Bob Phillips" ezt Ć*rta:

That is because in the first example you have the Find
arguments out of
order, LookIn comes before LookAt in the order. By specifying
the keywords
that doesn't matter, but when you don't specify them you need
to be in the
correct order.

So

lastcolumn = Cells.Find("*", Range("A1"),
xlValues, xlPart,
xlByColumns, xlPrevious, False).Column

should work

--
HTH

Bob Phillips

"Stefi" wrote in message
...
Hi All,
I'd like to understand the difference between these two
syntaxes below:

a./ lastcolumn = Cells.Find(What:="*", _
After:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlValues, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
This one works!

b./ lastcolumn = Cells.Find("*", Range("A1"),
xlPart,
xlValues, xlByColumns, xlPrevious, False).Column

This one does not work at the same place in the code, but
gives an error
message No. 1004 saying Find property of Class range not
accessible!

Regards,
Stefi







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
Using variables to make a date and using find method to find that. KyWilde Excel Programming 2 April 21st 05 09:43 PM
Macro syntax - how to find them mike b Excel Programming 1 April 11th 05 06:18 PM
Find method Kirk Excel Programming 0 September 22nd 04 09:33 PM
Find method benb Excel Programming 0 September 22nd 04 09:19 PM
Find method example Shinichi Excel Programming 3 August 22nd 03 10:39 PM


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