PC Review


Reply
Thread Tools Rate Thread

Aplication.Worksheetfunction.MAX() Stopped Working

 
 
Minitman
Guest
Posts: n/a
 
      9th Nov 2007
Greetings,

I have an invoice number generator on a UserForm run from a
CommandButton. Here is the code:

Dim rIN1 As Range
Dim rIN2 As Range

ThisWorkbook.Activate
Set rIN1 = Range("rInvNums_1st")
Set rIN2 = Range("rInvNums_List")
Input_1.Value = Application.WorksheetFunction.Max(rIN1, rIN2) + 1

With the named range "rInvNums_1st" equal to 3311000 (The first
possible invoice number minus 1) and the named range "rInvNums_List"
equal to the numbers in column C, (the list of existing invoice
numbers). This should produce the number 3311001 for the first
invoice number, instead it is producing the number 1!

When I check it with debug, debug shows the value of rIN1 as 3311000
and did not show anything for rIN2.

Anyone have any ideas as to what is wrong with this code?

Any help is greatly appreciated.

Thanks.

-Minitman
 
Reply With Quote
 
 
 
 
Minitman
Guest
Posts: n/a
 
      9th Nov 2007
I forgot to mention, Column C is at this time completely empty.

-Minitman

On Fri, 09 Nov 2007 01:05:17 -0600, Minitman
<(E-Mail Removed)> wrote:

>Greetings,
>
>I have an invoice number generator on a UserForm run from a
>CommandButton. Here is the code:
>
>Dim rIN1 As Range
>Dim rIN2 As Range
>
> ThisWorkbook.Activate
> Set rIN1 = Range("rInvNums_1st")
> Set rIN2 = Range("rInvNums_List")
> Input_1.Value = Application.WorksheetFunction.Max(rIN1, rIN2) + 1
>
>With the named range "rInvNums_1st" equal to 3311000 (The first
>possible invoice number minus 1) and the named range "rInvNums_List"
>equal to the numbers in column C, (the list of existing invoice
>numbers). This should produce the number 3311001 for the first
>invoice number, instead it is producing the number 1!
>
>When I check it with debug, debug shows the value of rIN1 as 3311000
>and did not show anything for rIN2.
>
>Anyone have any ideas as to what is wrong with this code?
>
>Any help is greatly appreciated.
>
>Thanks.
>
>-Minitman


 
Reply With Quote
 
Gary Keramidas
Guest
Posts: n/a
 
      9th Nov 2007
i entered 3311000 in D1 and named it rInvNums_1st
i named a range in column C1:C46 , C rInvNums_List . it is empty

i run this code and i get 3311001 as the result in the immediate window


Sub test()
Dim rIN1 As Range
Dim rIN2 As Range
Dim Input_1 As Long

ThisWorkbook.Activate
Set rIN1 = Range("rInvNums_1st")
Set rIN2 = Range("rInvNums_List")

Input_1 = Application.WorksheetFunction.Max(rIN1, rIN2) + 1
Debug.Print Input_1


End Sub


--


Gary


"Minitman" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
>I forgot to mention, Column C is at this time completely empty.
>
> -Minitman
>
> On Fri, 09 Nov 2007 01:05:17 -0600, Minitman
> <(E-Mail Removed)> wrote:
>
>>Greetings,
>>
>>I have an invoice number generator on a UserForm run from a
>>CommandButton. Here is the code:
>>
>>Dim rIN1 As Range
>>Dim rIN2 As Range
>>
>> ThisWorkbook.Activate
>> Set rIN1 = Range("rInvNums_1st")
>> Set rIN2 = Range("rInvNums_List")
>> Input_1.Value = Application.WorksheetFunction.Max(rIN1, rIN2) + 1
>>
>>With the named range "rInvNums_1st" equal to 3311000 (The first
>>possible invoice number minus 1) and the named range "rInvNums_List"
>>equal to the numbers in column C, (the list of existing invoice
>>numbers). This should produce the number 3311001 for the first
>>invoice number, instead it is producing the number 1!
>>
>>When I check it with debug, debug shows the value of rIN1 as 3311000
>>and did not show anything for rIN2.
>>
>>Anyone have any ideas as to what is wrong with this code?
>>
>>Any help is greatly appreciated.
>>
>>Thanks.
>>
>>-Minitman

>



 
Reply With Quote
 
=?Utf-8?B?QmFyYiBSZWluaGFyZHQ=?=
Guest
Posts: n/a
 
      9th Nov 2007
Might you have text in one of your ranges?
--
HTH,
Barb Reinhardt



"Minitman" wrote:

> I forgot to mention, Column C is at this time completely empty.
>
> -Minitman
>
> On Fri, 09 Nov 2007 01:05:17 -0600, Minitman
> <(E-Mail Removed)> wrote:
>
> >Greetings,
> >
> >I have an invoice number generator on a UserForm run from a
> >CommandButton. Here is the code:
> >
> >Dim rIN1 As Range
> >Dim rIN2 As Range
> >
> > ThisWorkbook.Activate
> > Set rIN1 = Range("rInvNums_1st")
> > Set rIN2 = Range("rInvNums_List")
> > Input_1.Value = Application.WorksheetFunction.Max(rIN1, rIN2) + 1
> >
> >With the named range "rInvNums_1st" equal to 3311000 (The first
> >possible invoice number minus 1) and the named range "rInvNums_List"
> >equal to the numbers in column C, (the list of existing invoice
> >numbers). This should produce the number 3311001 for the first
> >invoice number, instead it is producing the number 1!
> >
> >When I check it with debug, debug shows the value of rIN1 as 3311000
> >and did not show anything for rIN2.
> >
> >Anyone have any ideas as to what is wrong with this code?
> >
> >Any help is greatly appreciated.
> >
> >Thanks.
> >
> >-Minitman

>
>

 
Reply With Quote
 
Minitman
Guest
Posts: n/a
 
      11th Nov 2007
Hey Gary,

Thanks for the reply.

As you noted, there is nothing wrong with the code.

There was however something wrong with one of the named ranges -
rInvNums_1st.

This is the formula in the cell called rInvNums_1st:

=(YEAR(WBDate)-1974)&TEXT(MONTH(WBDate),"00")&TEXT(0,"000")

Which returned the number 3311000 for the workbook called 2007-11.xls,
this seemed to be working fine - but it wasn't!!! And that is what
was confusing me!

I needed to take the Value of this formula and pass that on like so:

=VALUE((YEAR(WBDate)-1974)&TEXT(MONTH(WBDate),"00")&TEXT(0,"000"))

Now it works.

Your confirmation that the code was working in the UserForm made me
look on the sheet at the named ranges. It was when I tried to get
MAX() to work in a cell and it was doing the same thing as the
UserForm, that I took a second look at the range rInvNums_1st. It
looked like it had the right result showing in the cell called
rInvNums_1st, but I could not get the MAX() formula to see it when I
used both ranges. So I tried the value command and it cleared up all
of the problems

-Minitman



On Fri, 9 Nov 2007 02:25:21 -0500, "Gary Keramidas"
<GKeramidasATmsn.com> wrote:

>i entered 3311000 in D1 and named it rInvNums_1st
>i named a range in column C1:C46 , C rInvNums_List . it is empty
>
>i run this code and i get 3311001 as the result in the immediate window
>
>
>Sub test()
>Dim rIN1 As Range
>Dim rIN2 As Range
>Dim Input_1 As Long
>
> ThisWorkbook.Activate
> Set rIN1 = Range("rInvNums_1st")
> Set rIN2 = Range("rInvNums_List")
>
> Input_1 = Application.WorksheetFunction.Max(rIN1, rIN2) + 1
>Debug.Print Input_1
>
>
>End Sub
>
>
>--
>
>
>Gary
>
>
>"Minitman" <(E-Mail Removed)> wrote in message
>news(E-Mail Removed)...
>>I forgot to mention, Column C is at this time completely empty.
>>
>> -Minitman
>>
>> On Fri, 09 Nov 2007 01:05:17 -0600, Minitman
>> <(E-Mail Removed)> wrote:
>>
>>>Greetings,
>>>
>>>I have an invoice number generator on a UserForm run from a
>>>CommandButton. Here is the code:
>>>
>>>Dim rIN1 As Range
>>>Dim rIN2 As Range
>>>
>>> ThisWorkbook.Activate
>>> Set rIN1 = Range("rInvNums_1st")
>>> Set rIN2 = Range("rInvNums_List")
>>> Input_1.Value = Application.WorksheetFunction.Max(rIN1, rIN2) + 1
>>>
>>>With the named range "rInvNums_1st" equal to 3311000 (The first
>>>possible invoice number minus 1) and the named range "rInvNums_List"
>>>equal to the numbers in column C, (the list of existing invoice
>>>numbers). This should produce the number 3311001 for the first
>>>invoice number, instead it is producing the number 1!
>>>
>>>When I check it with debug, debug shows the value of rIN1 as 3311000
>>>and did not show anything for rIN2.
>>>
>>>Anyone have any ideas as to what is wrong with this code?
>>>
>>>Any help is greatly appreciated.
>>>
>>>Thanks.
>>>
>>>-Minitman

>>


 
Reply With Quote
 
Minitman
Guest
Posts: n/a
 
      11th Nov 2007
Hey Barb,

Thanks for the reply.

A good question. however, the MAX() function doesn't care if there is
anything other then numbers, it simply ignores them. Or so says the
Microsoft help file.

I found the problem and explained it in detail in my reply to Gary
which I just posted. I needed the value of a formula that was in the
first named range.

A good place to start looking next time. <G>

-Minitman



On Fri, 9 Nov 2007 05:39:01 -0800, Barb Reinhardt
<(E-Mail Removed)> wrote:

>Might you have text in one of your ranges?
>--
>HTH,
>Barb Reinhardt


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with WorksheetFunction.Index and WorksheetFunction.Match Luke Microsoft Excel Programming 4 14th Oct 2009 12:57 AM
WorksheetFunction not working correctly Ayo Microsoft Excel Misc 1 23rd Jul 2008 05:48 PM
How do I open an aplication and run a file in that aplication use. =?Utf-8?B?Q296eQ==?= Microsoft Excel Programming 1 28th Mar 2005 10:41 AM
WorkSheetFunction.CountIf & WorkSheetFunction.SumIf with 2 conditions? Etien Microsoft Excel Programming 3 13th Jan 2004 04:07 PM
WorksheetFunction.CountIf and WorksheetFunction.SumIf with 2 conditions? Etien Microsoft Excel Worksheet Functions 4 12th Jan 2004 06:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:55 PM.