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 Apr 19th, 2002, 02:59 PM   #1
Bruce
New Member
 
Join Date: Apr 2002
Posts: 6
Default

I'm trying to write a macro that will consolidate all the worksheets.

The only way I have found is to list the actual worksheet names in the consolidation array line. The files I want to use this macro for are automatically created and the names may change so I can't hard code them in.
Bruce is offline   Reply With Quote
Old Apr 19th, 2002, 03:07 PM   #2
daleyman
Board Regular
 
Join Date: Mar 2002
Location: London, UK
Posts: 167
Default

what are you consolidating? does each sheet have identical width list with column headers in row 1? If so, try...



Sub consolidate_lists()
For sheetno = 2 To Sheets.Count
Sheets(sheetno).Rows("2:5").Copy
Sheets(1).Rows("2:2").Insert Shift:=xlDown
Next
End Sub

__________________

<table style="background-color:#0e54be" cellspacing="1" cellpadding="2"><td style="background-color:#ceffff;font-family:arial;color:#072c63;font-size:8pt;">***DALEY** :P**</td></table>
daleyman is offline   Reply With Quote
Old Apr 19th, 2002, 03:39 PM   #3
Bruce
New Member
 
Join Date: Apr 2002
Posts: 6
Default

The left column has product names and the top row has a column heading. Not all the products are on every worksheet. I need a way to add up the ones that are on multiple sheets (but different rows) and include the ones that are only on one sheet.

The consolidation function does this and I have it referencing the top and left cells for headings/columns.

Here is the code I have that does not work, it doesn't like my string in the array. But, if I type the string in it is fine.

(Works if I replace the last-
Array(ConRange) with
Array("Sheet1!R11C1:R27C4", "Sheet2!R11C1:R27C4", "Sheet3!R11C1:R27C4")

*****

GrpWorkSheets = Worksheets.Count
CurWorksheet = 2

Do While CurWorksheet <= GrpWorkSheets
Worksheets(CurWorksheet).Activate
sheetname = Worksheets(CurWorksheet).Name
rangename = Chr(34) & sheetname & Chr(33) & "R11C1:R27C4" & Chr(34) & ", "
ConRange = ConRange & rangename
CurWorksheet = CurWorksheet + 1
Loop

numChar = Len(ConRange)
numChar = numChar - 2
ConRange = Left(ConRange, numChar)
Worksheets(1).Activate
Range("A11").Select
Selection.Consolidate Sources:=Array(ConRange), Function:=xlSum, TopRow:=True, LeftColumn:=True, CreateLinks:=False

[ This Message was edited by: Bruce on 2002-04-19 14:42 ]
Bruce is offline   Reply With Quote
Old Apr 19th, 2002, 03:43 PM   #4
daleyman
Board Regular
 
Join Date: Mar 2002
Location: London, UK
Posts: 167
Default

haven't tested your code or really scrutinised but on first view looks like you're missing an exclamation mark in...

rangename = Chr(34) & sheetname & Chr(33) & "R11C1:R27C4" & Chr(34) & ", "


...ie...

rangename = Chr(34) & sheetname & Chr(33) & "!R11C1:R27C4" & Chr(34) & ", "


...if you are going to go about it this way.

__________________

<table style="background-color:#0e54be" cellspacing="1" cellpadding="2"><td style="background-color:#ceffff;font-family:arial;color:#072c63;font-size:8pt;">***DALEY** :P**</td></table>
daleyman is offline   Reply With Quote
Old Apr 19th, 2002, 03:46 PM   #5
Bruce
New Member
 
Join Date: Apr 2002
Posts: 6
Default

It didn't like the actual exclamtion mark in quotes so that's the chr(33).

For testing I had it place ConRange value in a cell and then copy/pasted it into the array line and everything worked fine. It doesn't like me referencing it with ConRange for some reason.
Bruce is offline   Reply With Quote
Old Apr 19th, 2002, 03:47 PM   #6
daleyman
Board Regular
 
Join Date: Mar 2002
Location: London, UK
Posts: 167
Default

i have abbreviated you code down to a few lines...



For worksheetno = 2 To Worksheets.Count
conRange = conRange & Sheets(worksheetno).Name & "!R11C1:R27C4" & Chr(34) & ","
Next

conRange = Left(conRange, Len(conRange) - 1)

Sheets(1).Range("A11").Consolidate Sources:=Array(conRange), Function:=xlSum, TopRow:=True, LeftColumn:=True, CreateLinks:=False



_________________

***DALEY** **


[ This Message was edited by: daleyman on 2002-04-19 14:48 ]

[ This Message was edited by: daleyman on 2002-04-19 14:49 ]
daleyman is offline   Reply With Quote
Old Apr 19th, 2002, 03:49 PM   #7
daleyman
Board Regular
 
Join Date: Mar 2002
Location: London, UK
Posts: 167
Default

okay, i see the chr(33) now, sorry. so then you should take out the chr(34) ????
__________________

<table style="background-color:#0e54be" cellspacing="1" cellpadding="2"><td style="background-color:#ceffff;font-family:arial;color:#072c63;font-size:8pt;">***DALEY** :P**</td></table>
daleyman is offline   Reply With Quote
Old Apr 19th, 2002, 03:54 PM   #8
daleyman
Board Regular
 
Join Date: Mar 2002
Location: London, UK
Posts: 167
Default

sorry, am just being stupid, ignore my last statement.

PS: why are you doing numChar=numChar-2, surely you only need strip one character?


_________________

***DALEY** **


[ This Message was edited by: daleyman on 2002-04-19 14:55 ]
daleyman is offline   Reply With Quote
Old Apr 19th, 2002, 03:56 PM   #9
Bruce
New Member
 
Join Date: Apr 2002
Posts: 6
Default

Your coding didn't mind the "!"

So now your coding is more effiecent (THANKS!!), but same issue.

I did the same test and added a temporary line to have the ConRange go into a cell and copy/pasted that into the coding and it worked perfect...still didn't work with ConRange being in there.

----
For worksheetno = 2 To Worksheets.Count
ConRange = ConRange & Chr(34) & Sheets(worksheetno).Name & "!R11C1:R27C4" & Chr(34) & ","
Next

ConRange = Left(ConRange, Len(ConRange) - 1)
Sheets(1).Range("A11").Consolidate Sources:=Array(ConRange), Function:=xlSum, TopRow:=True, LeftColumn:=True, CreateLinks:=False
Bruce is offline   Reply With Quote
Old Apr 19th, 2002, 03:57 PM   #10
Bruce
New Member
 
Join Date: Apr 2002
Posts: 6
Default

I was stripping a space I after the comma, it wasn't neccesary...just a little easier to read when viewing the string. Your coding just had the comma which is fine.
Bruce 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 12:46 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