MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Mar 11th, 2002, 12:41 PM   #1
Mopacs
New Member
 
Join Date: Mar 2002
Posts: 33
Default

Hello there,

I have a question regarding the creation of a pivot table. Is there a way to have excel (macro preferably) automatically determine the range of the source data (for a pivot table) without you having to specify a set coordinates (ie, A2:G2032). In this case the source data will fluctuate in the number of rows every week when I create this pivot table. So one week it may have 2000 rows, the next 1934 rows of data. Any suggestions would be greatly appreciated.

Thanks,

Rob
Mopacs is offline   Reply With Quote
Old Mar 11th, 2002, 12:50 PM   #2
karraj
Board Regular
 
Join Date: Mar 2002
Posts: 76
Default

You can have a cell with the value =counta(a:a) to get the last row of the table.
K
karraj is offline   Reply With Quote
Old Mar 11th, 2002, 12:51 PM   #3
Mark W.
MrExcel MVP
 
Join Date: Feb 2002
Location: Austin, Texas USA
Posts: 11,654
Default

The best approach is to create a named range (e.g., Database) and create your PivotTable using that range. You can either update there reference to this range as new data is added or make it dynamic.

[ This Message was edited by: Mark W. on 2002-03-11 11:51 ]
Mark W. is offline   Reply With Quote
Old Mar 11th, 2002, 12:57 PM   #4
Mopacs
New Member
 
Join Date: Mar 2002
Posts: 33
Default

Good suggestions.

Ok, lets say I specify the source data as a named range. What would be an example of the VBA code, which would dynamically determine the extent of the range each time?

Thanks,

Rob

[ This Message was edited by: Mopacs on 2002-03-11 11:59 ]
Mopacs is offline   Reply With Quote
Old Mar 11th, 2002, 03:13 PM   #5
Mark W.
MrExcel MVP
 
Join Date: Feb 2002
Location: Austin, Texas USA
Posts: 11,654
Default

Quote:
On 2002-03-11 11:57, Mopacs wrote:
Good suggestions.

Ok, lets say I specify the source data as a named range. What would be an example of the VBA code, which would dynamically determine the extent of the range each time?

Thanks,

Rob

[ This Message was edited by: Mopacs on 2002-03-11 11:59 ]
No VBA code is required. You either update the data list using Excel's built-in data form (i.e., the Data | Form... menu command) or you define a name that refers to a formula that examines the key field(s) of your data list to determine the extent of the data list.

[ This Message was edited by: Mark W. on 2002-03-11 14:44 ]
Mark W. is offline   Reply With Quote
Old Mar 12th, 2002, 09:59 AM   #6
Mopacs
New Member
 
Join Date: Mar 2002
Posts: 33
Default

Quote:
On 2002-03-11 14:13, Mark W. wrote:


No VBA code is required. You either update the data list using Excel's built-in data form (i.e., the Data | Form... menu command) or you define a name that refers to a formula that examines the key field(s) of your data list to determine the extent of the data list.

[ This Message was edited by: Mark W. on 2002-03-11 14:44 ]
Well you'll have to excuse my lack of knowledge here, but do you have an example of a formula that would examine the key fields of a range? I'm not sure I completely understand how to do that. So you create a named range?

Thanks,

Rob
Mopacs is offline   Reply With Quote
Old Mar 12th, 2002, 10:03 AM   #7
lenze
MrExcel MVP
 
lenze's Avatar
 
Join Date: Feb 2002
Location: Helena, MT
Posts: 13,690
Default

Here is a sample of how to assign a dynamic named range.

Dynamic Range Formula
=Sheet1!$A$1:OFFSET(Sheet1!$A$1,COUNTA(Sheet1!$A$1:$A$65536)-1,COUNTA(Sheet1!$1:$1)-1)
Note: $A$1= Anchor Cell Address (Change as needed)
Sheet1!$1:$1 Anchor Row Number (Change as needed)
The above formula gives a dynamic range that expands both by rows and columns, using the entire column or row. To limit the number of rows, change 65536 to a lower number (ex. 1000 will limit the range to 999 rows) To limit the number of columns, change the Sheet1!$1:$1 to Sheet1!$A$1:$Col :$1, where Col is the column letter of the last column you want in the range. To use, Choose Insert Name Define. Type a name for your range in the name box and then enter the above formula (with any adjustments) in the refers to field. Change Sheet1! in the formula as necessary






[ This Message was edited by: lenze on 2002-03-12 09:04 ]

[ This Message was edited by: lenze on 2002-03-12 09:05 ]
lenze is offline   Reply With Quote
Old Mar 12th, 2002, 10:07 AM   #8
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

Hi


I have many examples of Dynamic named ranges here that are ideal for Pivot Tables.

http://www.ozgrid.com/Excel/DynamicRanges.htm
Dave Hawley is offline   Reply With Quote
Old Mar 12th, 2002, 10:27 AM   #9
Mark W.
MrExcel MVP
 
Join Date: Feb 2002
Location: Austin, Texas USA
Posts: 11,654
Default

Quote:
On 2002-03-12 08:59, Mopacs wrote:
Well you'll have to excuse my lack of knowledge here, but do you have an example of a formula that would examine the key fields of a range? I'm not sure I completely understand how to do that. So you create a named range?

Thanks,

Rob
Can you provide a sample (10-15 rows) of your data including headers? An easy way to do this is to select an unused cell, type =, select a range of records, press F9, and paste the contents of the formula bar into a reply posting.
Mark W. is offline   Reply With Quote
Old Mar 12th, 2002, 10:45 AM   #10
Mopacs
New Member
 
Join Date: Mar 2002
Posts: 33
Default

Quote:
On 2002-03-12 09:27, Mark W. wrote:

Can you provide a sample (10-15 rows) of your data including headers? An easy way to do this is to select an unused cell, type =, select a range of records, press F9, and paste the contents of the formula bar into a reply posting.
Ok, it looks lenze's example above seems to have worked. I understand the logic, and thats basically what I was looking for.. but I'm open to any additional suggestions of course....

Here is a sample cropping of this data/worksheet..not all columns are represented either. But lets just say the first field heading below is in column A..and the Row headers lie in Row 3. I dont know if this is what you were looking for, but here ya go:

{"Age","dob","Age_Cat","Age_Grp","TP","BP";49,19244,"Adult"," 45-64","23","13";82,7314,"Aged"," 80-84","13","13";66,13010,"Aged"," 65-69","13","13";75,9707,"Aged"," 75-79","13","13";61,14802,"Adult"," 45-64","13","13";82,7094,"Aged"," 80-84","13","13";72,11002,"Aged"," 70-74","23","13";67,12698,"Aged"," 65-69","14","13"}

Thank you (all of you) for your assistance here.

Rob




[ This Message was edited by: Mopacs on 2002-03-12 09:46 ]

[ This Message was edited by: Mopacs on 2002-03-12 09:47 ]
Mopacs is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 09:53 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes