View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Bigfoot17 Bigfoot17 is offline
external usenet poster
 
Posts: 67
Default VBA Sumproduct Help

I have a formula currently in cell G3 working fine, it goes out to another
file and returns a sumproduct:
=SUMPRODUCT(--('X:\unit 01\Equipment\[unit 1
Froster.xls]Roster'!$J$3:$J$300="x"),--(MONTH('X:\unit 01\Equipment\[unit 1
Froster.xls]Roster'!$P$3:$P$300)=1),--(YEAR('X:\unit 01\Equipment\[unit 1
FRoster.xls]Roster'!$P$3:$P$300)=$F$2))
There are perhpas 35 other similar formulas in other cells.

What I am trying to do is write some VBA so that when the program is run it
calculates the sumproduct. But I am struggling with the syntax to get the
formula in. This does not work of course:
Range("G" & (topRow + cTab)).Formula = "=SUMPRODUCT(--('X:\unit
01\Equipment\[unit 1 Froster.xls]Roster'!$J$3:$J$300="x"),--(MONTH('X:\unit
01\Equipment\[unit 1 Froster.xls]Roster'!$P$3:$P$300)=1),--(YEAR('X:\unit
01\Equipment\[unit 1 FRoster.xls]Roster'!$P$3:$P$300)=$F$2))"

Then to make matter harder I want to use variables for the filename. I have
defined eslewhere the path and filenames.

I am really struggling with the proper syntax converting double quotes to
single quotes etc. Anty assistance is appreciated.