Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Variable for Worksheet Name & Syntax for use in formula

I need to assign a variable for the Worksheet Name property each time
this module is run and use that variable in a SUMPRODUCT formula. The
worksheet Name will be different each time the module is run.

Below are four lines from my code module. I suspect my problem is poor
syntax in the formula code.

Dim FPsh As String

FPsh = ActiveSheet.Name

Worksheets("2005").Select

Range("E6").Formula = "=SUMPRODUCT((" & FPsh & "!$E$1:$E$1000=$C6)*" &
"(" & FPsh & "!$B$1:$B$1000(--(""2004/12/31"")))*" & "((" & FPsh &
"!$B$1:$B$1000<(--(G$4))))*" & "(((" & FPsh & "!$J$1:$J$1000)" & ")"

Runtime error occurs at the formula line (above). Help appreciated in
advance...Mike

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Variable for Worksheet Name & Syntax for use in formula

Not enough closing brackets


Range("E6").Formula = "=SUMPRODUCT((" & FPsh & "!$E$1:$E$1000=$C6)*" & _
"(" & FPsh & "!$B$1:$B$1000(--(""2004/12/31"")))*" & "((" & FPsh & _
"!$B$1:$B$1000<(--(G$4))))*" & "(((" & FPsh & "!$J$1:$J$1000)" & ")))"

but you don't need all those brackets anyway

Range("E6").Formula = "=SUMPRODUCT((" & FPsh & "!$E$1:$E$1000=$C6)*" & _
"(" & FPsh & "!$B$1:$B$1000--""2004-12-31"")*" & "(" & FPsh & _
"!$B$1:$B$1000<--G$4)*" & "(" & FPsh & "!$J$1:$J$1000))"

I'm not convinced that you need the doiuble-unary before G4, but without
seeing your data, I left it.


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Mike" wrote in message
ups.com...
I need to assign a variable for the Worksheet Name property each time
this module is run and use that variable in a SUMPRODUCT formula. The
worksheet Name will be different each time the module is run.

Below are four lines from my code module. I suspect my problem is poor
syntax in the formula code.

Dim FPsh As String

FPsh = ActiveSheet.Name

Worksheets("2005").Select

Range("E6").Formula = "=SUMPRODUCT((" & FPsh & "!$E$1:$E$1000=$C6)*" &
"(" & FPsh & "!$B$1:$B$1000(--(""2004/12/31"")))*" & "((" & FPsh &
"!$B$1:$B$1000<(--(G$4))))*" & "(((" & FPsh & "!$J$1:$J$1000)" & ")"

Runtime error occurs at the formula line (above). Help appreciated in
advance...Mike



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
VBA Syntax for using a variable in a worksheet function xjetjockey Excel Discussion (Misc queries) 3 January 9th 07 04:23 AM
syntax when using a variable in a formula anny Excel Programming 2 May 8th 06 04:09 PM
syntax for variable adamaagard Excel Programming 2 January 20th 06 12:45 AM
For each syntax using a worksheet array variable Ralph Heidecke[_2_] Excel Programming 1 April 5th 05 12:42 AM
Syntax using variable in cell Formula Mike Fogleman Excel Programming 2 January 28th 04 12:47 AM


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