Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Using SUMPRODUCT where one of the columns can be either TEST or aNUMBER

I am executing the following SUMPRODUCT string in VBA, which works
fine:

SumProduct((TUESDAY!$D$2:$D$35=7659)*(TUESDAY!$E$2 :$E$35="Yes")*
(TUESDAY!$M$2:$M$35))

My problem is that column "D" (being tested in this case for 7659
(which changes as it is a variable used to build the above string) in
this case is a number. This can sometimes start with a letter (i.e.
W####), in which case I need to put quotes into my formula around the
first variable (which is "7659" in the example above). However, if I
want the variable to be a number (as in the example above), the
SumProduct function will return 0 if I put quotes around it since it
is evaluated as a number (even if I have the Type as Text for column
"D").

My question:

Is there a way to have this function work either way, or do I need to
test my variable to see if it is a Number or a String and
conditionally form my SumProduct string accordingly?

Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Using SUMPRODUCT where one of the columns can be either TEST or aNUMBER

I think I'd test for a real number...

Dim myVar As Variant
Dim QtMark As String

myVar = "1234" ' or "a1234"

If TypeName(myVar) = "String" Then
'it's a string, add the double quotes
QtMark = """"
Else
'it's not a string
QtMark = ""
End If

Then build your formula with the variable surrounded by QtMark.









jtertin wrote:

I am executing the following SUMPRODUCT string in VBA, which works
fine:

SumProduct((TUESDAY!$D$2:$D$35=7659)*(TUESDAY!$E$2 :$E$35="Yes")*
(TUESDAY!$M$2:$M$35))

My problem is that column "D" (being tested in this case for 7659
(which changes as it is a variable used to build the above string) in
this case is a number. This can sometimes start with a letter (i.e.
W####), in which case I need to put quotes into my formula around the
first variable (which is "7659" in the example above). However, if I
want the variable to be a number (as in the example above), the
SumProduct function will return 0 if I put quotes around it since it
is evaluated as a number (even if I have the Type as Text for column
"D").

My question:

Is there a way to have this function work either way, or do I need to
test my variable to see if it is a Number or a String and
conditionally form my SumProduct string accordingly?

Thanks!


--

Dave Peterson
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
How to prevent a number stored as text from converting to anumber Aaron Rubinstein Excel Programming 0 August 15th 09 12:20 AM
Sumproduct with weekend day test Loge Excel Worksheet Functions 4 December 10th 08 06:47 AM
SumProduct but sometimes don't test some criteria Aaron Excel Worksheet Functions 20 March 2nd 08 08:42 PM
Function for finding a cell with Anumber in it steve Excel Worksheet Functions 3 November 4th 07 01:45 PM
Using a formula on anumber of cells in a column that the user inpu Charissa Excel Discussion (Misc queries) 1 October 30th 06 08:30 PM


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