Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Can someone explain why?

Hi,
Here is the situation:
I use EXCEL 2003

If I apply the following it does not work:
-------------------------------------------------------

Sub test()
Dim maxnumber As Integer, rngMax As Range

Sheets("Planif-max52").Select
Set rngMax = Worksheets("Rap-ELC").Range("B2:B53")
maxnumber = Application.WorksheetFunction.Max(rngMax)
MsgBox maxnumber

End Sub

But this does with the ActiveSheet.Range
--------------------
Sub test()
Dim maxnumber As Integer, rngMax As Range

Sheets("Planif-max52").Select
Set rngMax = ActiveSheet.Range("B2:B53")
maxnumber = Application.WorksheetFunction.Max(rngMax)
MsgBox maxnumber

End Sub


P.S: The column is define as General

Thank's ahead
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Can someone explain why?

Bobby,

Well it depends on your definition of 'Doesn't work'.

Both sub returns the maximum value in the range rngMax, what do you expect
them to do? What result are you getting?

Mike


"Bobby" wrote:

Hi,
Here is the situation:
I use EXCEL 2003

If I apply the following it does not work:
-------------------------------------------------------

Sub test()
Dim maxnumber As Integer, rngMax As Range

Sheets("Planif-max52").Select
Set rngMax = Worksheets("Rap-ELC").Range("B2:B53")
maxnumber = Application.WorksheetFunction.Max(rngMax)
MsgBox maxnumber

End Sub

But this does with the ActiveSheet.Range
--------------------
Sub test()
Dim maxnumber As Integer, rngMax As Range

Sheets("Planif-max52").Select
Set rngMax = ActiveSheet.Range("B2:B53")
maxnumber = Application.WorksheetFunction.Max(rngMax)
MsgBox maxnumber

End Sub


P.S: The column is define as General

Thank's ahead

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Can someone explain why?

On Apr 18, 8:28*am, "Don Guillett" wrote:
I tested yours and it gave me the max. What does "it does not work" mean?

*Why not just use.

Sub maxinothersheet()
*MsgBox Application.Max(Sheets("a b").Range("e2:e22"))
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
"Bobby" wrote in message

...



Hi,
Here is the situation:
I use EXCEL 2003


If I apply the following it does not work:
-------------------------------------------------------


Sub test()
* *Dim maxnumber As Integer, rngMax As Range


* *Sheets("Planif-max52").Select
* *Set rngMax = Worksheets("Rap-ELC").Range("B2:B53")
* *maxnumber = Application.WorksheetFunction.Max(rngMax)
* * MsgBox maxnumber


End Sub


But this does with the ActiveSheet.Range
--------------------
Sub test()
* *Dim maxnumber As Integer, rngMax As Range


* *Sheets("Planif-max52").Select
* *Set rngMax = ActiveSheet.Range("B2:B53")
* *maxnumber = Application.WorksheetFunction.Max(rngMax)
* * MsgBox maxnumber


End Sub


P.S: The column is define as General


Thank's ahead- Hide quoted text -


- Show quoted text -


Ok,
I meet that in the first example I get a zero value even if I have 500
for qty in the range. But if I use the ActiveSheet.Range I get the
500 value. Saying that if it works with you then I must be doing
something wrong!
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,059
Default Can someone explain why?

"Bobby" wrote:
If I apply the following it does not work:
[....]
Sheets("Planif-max52").Select
Set rngMax = Worksheets("Rap-ELC").Range("B2:B53")
maxnumber = Application.WorksheetFunction.Max(rngMax)


In this case, you are looking at B2:B53 in worksheet Rap-ECL.


But this does with the ActiveSheet.Range
[....]
Sheets("Planif-max52").Select
Set rngMax = ActiveSheet.Range("B2:B53")
maxnumber = Application.WorksheetFunction.Max(rngMax)


In this case, you are looking at B2:B53 in worksheet Planif-max52.


In a later posting, "Bobby" wrote:
in the first example I get a zero value even
if I have 500 for qty in the range. But if I use the
ActiveSheet.Range I get the 500 value.


When you say "the 500 value", I get the impression you think you are looking
at the same B2:B53 in both implementations. That is not the case. Could
that explain your problem?

In any case, in Excel, go to both worksheets, and enter =MAX(B2:B53) in a
cell to confirm your expectations.


----- original posting -----

"Bobby" wrote in message
...
Hi,
Here is the situation:
I use EXCEL 2003

If I apply the following it does not work:
-------------------------------------------------------

Sub test()
Dim maxnumber As Integer, rngMax As Range

Sheets("Planif-max52").Select
Set rngMax = Worksheets("Rap-ELC").Range("B2:B53")
maxnumber = Application.WorksheetFunction.Max(rngMax)
MsgBox maxnumber

End Sub

But this does with the ActiveSheet.Range
--------------------
Sub test()
Dim maxnumber As Integer, rngMax As Range

Sheets("Planif-max52").Select
Set rngMax = ActiveSheet.Range("B2:B53")
maxnumber = Application.WorksheetFunction.Max(rngMax)
MsgBox maxnumber

End Sub


P.S: The column is define as General

Thank's ahead




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Can someone explain why?

Set rngMax = Worksheets("Rap-ELC").Range("B2:B53")

Do you have values int B2:B53 of this worksheet? If it is returning zero
then it is checking something. If your sheet name was misspelled you would
get an error message. The code looks OK.

"Bobby" wrote:

Hi,
Here is the situation:
I use EXCEL 2003

If I apply the following it does not work:
-------------------------------------------------------

Sub test()
Dim maxnumber As Integer, rngMax As Range

Sheets("Planif-max52").Select
Set rngMax = Worksheets("Rap-ELC").Range("B2:B53")
maxnumber = Application.WorksheetFunction.Max(rngMax)
MsgBox maxnumber

End Sub

But this does with the ActiveSheet.Range
--------------------
Sub test()
Dim maxnumber As Integer, rngMax As Range

Sheets("Planif-max52").Select
Set rngMax = ActiveSheet.Range("B2:B53")
maxnumber = Application.WorksheetFunction.Max(rngMax)
MsgBox maxnumber

End Sub


P.S: The column is define as General

Thank's ahead

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
Not sure how to explain.... Tricia LeAnn[_2_] Excel Discussion (Misc queries) 12 January 18th 08 07:14 PM
Please explain Maxwell Excel Worksheet Functions 1 March 31st 06 01:12 PM
How to explain??... tagr Excel Discussion (Misc queries) 2 March 18th 06 03:34 AM
Let me see if I can explain this... jsc3489 Excel Worksheet Functions 0 July 22nd 05 05:04 PM
Can someone explain to me? Pls? stevetan2010[_4_] Excel Programming 3 November 16th 04 08:18 AM


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