Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default maximum of currency array?

I lift a worksheet range into an array and determine its maximum but it
doesn't work, the results is always zero (its initial value):

Sub curtest()
Dim currencyarray As Variant
Dim currencymax As Variant
currencyarray = Range("A1:C1").Value
currencymax = Application.Max(currencyarray)
MsgBox currencymax
End Sub

If I first convert the cells number format (manually in the worksheet
itself) from Currency to General or Number than it *does* work.

So I thought of converting the complete currency array (in VBA, like to
singles) but I don't see a way how to do that. One possibility I guess would
be to iterate through each array element but this seems a long detour (I need
to work this on many long currency ranges).

Is there a simpler solution? Thanks very much!

-Joni
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default maximum of currency array?

Dear Joni

Please try the below

Sub curtest()
Dim currencyarray As Variant
Dim currencymax As Variant

Set currencyarray = Range("A1:C1")
currencymax = WorksheetFunction.Max(currencyarray)
MsgBox currencymax

End Sub


If this post helps click Yes
---------------
Jacob Skaria


"jonigr" wrote:

I lift a worksheet range into an array and determine its maximum but it
doesn't work, the results is always zero (its initial value):

Sub curtest()
Dim currencyarray As Variant
Dim currencymax As Variant
currencyarray = Range("A1:C1").Value
currencymax = Application.Max(currencyarray)
MsgBox currencymax
End Sub

If I first convert the cells number format (manually in the worksheet
itself) from Currency to General or Number than it *does* work.

So I thought of converting the complete currency array (in VBA, like to
singles) but I don't see a way how to do that. One possibility I guess would
be to iterate through each array element but this seems a long detour (I need
to work this on many long currency ranges).

Is there a simpler solution? Thanks very much!

-Joni

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default maximum of currency array?

Sub curtest()
Dim currencyarray As Variant
Dim currencymax As Variant
currencyarray = Range("A1:C1").Value
currencymax = Application.Max(currencyarray)
MsgBox currencymax
End Sub


Your code (above) worked correctly for me if the numbers you are looking for
are on the active sheet. Perhaps it would be better to qualify your Range
reference with the Worksheet you want to get it from. Assign your value to
currencyarray like this (where I have assumed the cells you are interested
in are on Sheet1)...

currencyarray = Worksheets("Sheet1").Range("A1:C1").Value

--
Rick (MVP - Excel)


"jonigr" wrote in message
...
I lift a worksheet range into an array and determine its maximum but it
doesn't work, the results is always zero (its initial value):

Sub curtest()
Dim currencyarray As Variant
Dim currencymax As Variant
currencyarray = Range("A1:C1").Value
currencymax = Application.Max(currencyarray)
MsgBox currencymax
End Sub

If I first convert the cells number format (manually in the worksheet
itself) from Currency to General or Number than it *does* work.

So I thought of converting the complete currency array (in VBA, like to
singles) but I don't see a way how to do that. One possibility I guess
would
be to iterate through each array element but this seems a long detour (I
need
to work this on many long currency ranges).

Is there a simpler solution? Thanks very much!

-Joni


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default maximum of currency array?

Currency and Dates are strange.

Try:

currencyarray = Range("A1:C1").Value2

VBA's help on Value2 will explain, er, describe the situation.

jonigr wrote:

I lift a worksheet range into an array and determine its maximum but it
doesn't work, the results is always zero (its initial value):

Sub curtest()
Dim currencyarray As Variant
Dim currencymax As Variant
currencyarray = Range("A1:C1").Value
currencymax = Application.Max(currencyarray)
MsgBox currencymax
End Sub

If I first convert the cells number format (manually in the worksheet
itself) from Currency to General or Number than it *does* work.

So I thought of converting the complete currency array (in VBA, like to
singles) but I don't see a way how to do that. One possibility I guess would
be to iterate through each array element but this seems a long detour (I need
to work this on many long currency ranges).

Is there a simpler solution? Thanks very much!

-Joni


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default maximum of currency array?

Wow, great help!

Both Jacob's and Dave's suggestions work, Very similar apparently, both turn
currencymax into a double (that's fine).

Thanks very much!

-Joni
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
Maximum number of elements in array Juarez Excel Discussion (Misc queries) 1 December 9th 08 07:49 PM
Referencing a row with a maximum value array? pete Excel Programming 1 May 23rd 08 06:35 PM
Finding Location of Maximum Value in 2D Array [email protected] Excel Discussion (Misc queries) 17 November 10th 06 02:36 PM
Finding Location of Maximum Value in 2D Array [email protected] Excel Worksheet Functions 15 November 9th 06 05:23 AM
Can you identify the maximum value in an array? Brad Patterson Excel Programming 5 July 11th 03 12:08 AM


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