Range in Formula messes up with Query refresh

aka_krakur

Active Member
Joined
Jan 31, 2006
Messages
438
I have one worksheet (ReportableQuery) that populates via a Microsoft Query.
Another worksheet (ChartData) has a cell with the following formula in cell B9 (through V9 respectively)

Code:
=(SUMPRODUCT(--(MMULT(--ISNUMBER(SEARCH(ChartData!$B$4:$E$4,ReportableQuery!$W$25:$W$2052))+0,ROW(ReportableQuery!$W$25:INDEX(ReportableQuery!$W$25:$W$2052,COLUMNS(ChartData!$B$4:$E$4)))^0)>0),--(MMULT(--ISNUMBER(SEARCH(ChartData!$A$4,ReportableQuery!$L$25:$L$2052))+0,ROW(ReportableQuery!$L$25:INDEX(ReportableQuery!$L$25:$L$2052,COLUMNS(ChartData!$A$4)))^0)>0),--(ReportableQuery!$I$25:$I$2052-DAY(ReportableQuery!$I$25:$I$2052)+1=ChartData!C$7)))

The formula itself works great (can't remember who to give kudos to but someone on this forum helped me with that one)

However, when I do a Data Refresh on the query on the RepoortableQuery worksheet, somehow the formula changes to $W$25:$W$25.

Note: the query is run by a number of Macros in VB that has a userform that collects the info for the query parameters, etc.
Part of that VB Macro deletes the data from the query 1st (Because there are non-query columns with formulas that have to be re-input)
So I'm guessing by the VB deleting the rows that were originally in this formula automatically updates the formula on the other worksheet to say "my range changed".
I tried writing a VB to repopulate these formulas on the ChartData worksheet (Cell B9) but I believe the formula's too long or something for VB.
Anyway, with all that said, any suggestions?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

bjwillingham

Active Member
Joined
Jun 17, 2003
Messages
287
Define a dynamic range.

Define $W$25 as "DataUL" (data upper left)

Define a name "Data" refersto: =offset(dataul,0,0,counta(W:W),1)

No matter how many rows are returned, 'data' will always contain the enitire set of rows.
 

aka_krakur

Active Member
Joined
Jan 31, 2006
Messages
438
Then, in the formula as seen above do I change the ranges to something like this?
Code:
...(ReportableQuery!DataUL:Data)...
 

aka_krakur

Active Member
Joined
Jan 31, 2006
Messages
438
I know how to define the dynamic range; however, how do I use the defined names in my current formula?

I tried taking out the ranges as they appear in the formula currently:
Code:
=(SUMPRODUCT(--(MMULT(--ISNUMBER(SEARCH(ChartData!$B$4:$E$4,ReportableQuery!$W$25:$W$2052))+0,ROW(ReportableQuery!$W$25:INDEX(ReportableQuery!$W$25:$W$2052,COLUMNS(ChartData!$B$4:$E$4)))^0)>0),--(MMULT(--ISNUMBER(SEARCH(ChartData!$A$4,ReportableQuery!$L$25:$L$2052))+0,ROW(ReportableQuery!$L$25:INDEX(ReportableQuery!$L$25:$L$2052,COLUMNS(ChartData!$A$4)))^0)>0),--(ReportableQuery!$I$25:$I$2052-DAY(ReportableQuery!$I$25:$I$2052)+1=ChartData!C$7)))
and replaced them with the defined names and it made the formula look like this:
Code:
=(SUMPRODUCT(--(MMULT(--ISNUMBER(SEARCH(ChartData!$B$4:$E$4,'TEMPLATEProductFamily-ReportedCode-Test.xls'!DataUL:Data))+0,ROW('TEMPLATEProductFamily-ReportedCode-Test.xls'!DataUL:INDEX('TEMPLATEProductFamily-ReportedCode-Test.xls'!DataUL:Data,COLUMNS(ChartData!$B$4:$E$4)))^0)>0),--(MMULT(--ISNUMBER(SEARCH(ChartData!$A$4,'TEMPLATEProductFamily-ReportedCode-Test.xls'!PF_DataUL:PF_Data))+0,ROW('TEMPLATEProductFamily-ReportedCode-Test.xls'!PF_DataUL:INDEX('TEMPLATEProductFamily-ReportedCode-Test.xls'!PF_DataUL:PF_Data,COLUMNS(ChartData!$A$4)))^0)>0),--('TEMPLATEProductFamily-ReportedCode-Test.xls'!Date_DataUL:Date_Data-DAY('TEMPLATEProductFamily-ReportedCode-Test.xls'!Date_DataUL:Date_Data)+1=ChartData!C$7)))
It returns a value of #REF!

Please help.

Thanks
 

aka_krakur

Active Member
Joined
Jan 31, 2006
Messages
438
New problem with the Defined dyamic ranges.
When I look at the "Data" defined ranges (ie. Data, PF_Data, Date_Data)
the ranges always go over the data by like 2 rows. I can't have any blanks, because I've tested my formula above both ways. One with over-extending into blank rows and once without and the only time the formula works is when the search is searching in ranges with definite data.

I can't quite figure out why the dynamic ranges are going over like that. Any ideas?
 

Forum statistics

Threads
1,141,098
Messages
5,704,319
Members
421,338
Latest member
Pepess

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top