Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default SUMPRODUCT in VBA

I'm trying to count the occurance of a specified first three letters
in a list of values in a column. On the spreadsheet level, I can use:

= SUMPRODUCT(--(LEFT(TRIM(UPPER(C3:C1000)),3)="RED"))


When I try this in VBA, I get an syntax error.

Application.SUMPRODUCT(--(LEFT(TRIM(UPPER(C3:C1000)),3)="RED"))
OR
Worksheetfunction.SUMPRODUCT(--(LEFT(TRIM(UPPER(C3:C1000)),
3)="RED"))


Can someone explain what I'm doing wrong? I don't need to use
SUMPRODUCT, if something else like COUNTIF will work with the LEFT,
TRIM, and UPPER.

Thanks.

John

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default SUMPRODUCT in VBA

I believe I've seen people use
Execute(Sumproduct .. )



"robotman" wrote:

I'm trying to count the occurance of a specified first three letters
in a list of values in a column. On the spreadsheet level, I can use:

= SUMPRODUCT(--(LEFT(TRIM(UPPER(C3:C1000)),3)="RED"))


When I try this in VBA, I get an syntax error.

Application.SUMPRODUCT(--(LEFT(TRIM(UPPER(C3:C1000)),3)="RED"))
OR
Worksheetfunction.SUMPRODUCT(--(LEFT(TRIM(UPPER(C3:C1000)),
3)="RED"))


Can someone explain what I'm doing wrong? I don't need to use
SUMPRODUCT, if something else like COUNTIF will work with the LEFT,
TRIM, and UPPER.

Thanks.

John


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default SUMPRODUCT in VBA

application.Countif(Range("C3:C1000"),"RED*")

this is case insensitive so both RED and red would be counted.

--
Regards,
Tom Ogilvy

"robotman" wrote in message
oups.com...
I'm trying to count the occurance of a specified first three letters
in a list of values in a column. On the spreadsheet level, I can use:

= SUMPRODUCT(--(LEFT(TRIM(UPPER(C3:C1000)),3)="RED"))


When I try this in VBA, I get an syntax error.

Application.SUMPRODUCT(--(LEFT(TRIM(UPPER(C3:C1000)),3)="RED"))
OR
Worksheetfunction.SUMPRODUCT(--(LEFT(TRIM(UPPER(C3:C1000)),
3)="RED"))


Can someone explain what I'm doing wrong? I don't need to use
SUMPRODUCT, if something else like COUNTIF will work with the LEFT,
TRIM, and UPPER.

Thanks.

John



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default SUMPRODUCT in VBA

Thanks for the CountIf syntax. Good thing it's not case sensitive.

Since I may have leading spaces, I had to add a "*" to the condition
"*RED*" since I can't embed the TRIM inside the CountIf. But this
will work fine since "RED" doesn't appear in parts of other words in
the column.

Thanks again!

John



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
Sumproduct with Condition OR Sumproduct with ADDRESS function - HE gholly Excel Discussion (Misc queries) 2 September 28th 09 05:07 PM
sumproduct - < Rick Excel Discussion (Misc queries) 5 July 5th 09 03:45 PM
Conditional SUMPRODUCT or SUMPRODUCT with Filters Ted M H Excel Worksheet Functions 4 August 14th 08 07:50 PM
sumproduct? sumif(sumproduct)? David Excel Worksheet Functions 3 July 13th 07 07:06 PM
sumproduct? JR Excel Worksheet Functions 1 February 4th 06 08:33 AM


All times are GMT +1. The time now is 06:50 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"