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 18th, 2002, 10:43 AM   #1
kluitna
Board Regular
 
Join Date: Mar 2002
Posts: 75
Default

A quick question on setting up variables in a formula.

I have the current formula:

ActiveCell.FormulaR1C1 = "='" & strfile & "'!R21C4"

I am using it to link several workbooks together. That have several worksheets in them.

"strfile" is the workbook file name, This works just fine. My problem is I can't seem to get the formula on the next pass throughthe loop to look at the next worksheet in "strfile". Does anyone know the syntax to look at the same file and the next sheet in a file.?

Any ideas are much appreciated.
kluitna is offline   Reply With Quote
Old Mar 18th, 2002, 10:57 AM   #2
Al Chara
MrExcel MVP
 
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
Default

The following code should help to get the worksheet names:

Set STRFILE = ThisWorkbook
For I = 1 To ThisWorkbook.Worksheets.Count
MsgBox STRFILE.Worksheets(I).Name
Next I

If you need help to apply this to your situation, then post again.

Hope this helps.
Kind regards, Al.

[ This Message was edited by: Al Chara on 2002-03-18 10:57 ]
Al Chara is offline   Reply With Quote
Old Mar 18th, 2002, 11:39 AM   #3
kluitna
Board Regular
 
Join Date: Mar 2002
Posts: 75
Default

kluitna is offline   Reply With Quote
Old Mar 18th, 2002, 12:02 PM   #4
kluitna
Board Regular
 
Join Date: Mar 2002
Posts: 75
Default

You have me on the right track Al. The problem is when I use the command Thisworkbook, it trys to look into the active workbook which is the one I am trying to link the data into.

ActiveCell.FormulaR1C1 = "='[Est Source Item.xls]Estimate (1)'!R21C4"

Above is the formula with the hard values in it for the given soucre file and sheet number. There is as many as 70 source files and each one has 30 estimates. I can loop though the source files with out a problem, but when but hav e not been able to successfuly right a loop inside the source file loop to go through each estimate.

Hope this is clearer, it seems very simple but for some reason it eludes my even simpler mind.
kluitna is offline   Reply With Quote
Old Mar 18th, 2002, 12:27 PM   #5
Al Chara
MrExcel MVP
 
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
Default

Are the workbooks all open when you want to run this macro?
Al Chara is offline   Reply With Quote
Old Mar 18th, 2002, 12:33 PM   #6
kluitna
Board Regular
 
Join Date: Mar 2002
Posts: 75
Default

Al, The only workbooks that are open is the one I am getting the the data from and the one I am liking to, Just had thought, the one I am gettinf the date from does not have to be open to establish the link. Or does it?

kluitna is offline   Reply With Quote
Old Mar 18th, 2002, 01:32 PM   #7
Al Chara
MrExcel MVP
 
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
Default

Does this help:

Dim strfile As Workbook
For h = 1 To Workbooks.Count
Set strfile = Workbooks(h)
For i = 1 To strfile.Worksheets.Count
ActiveCell.Value = strfile.Worksheets(i).Range("d24")
ActiveCell.Offset(1, 0).Select
Next i
Next h

The code loops through all the open workbooks and their sheets and places cell D24 in the activecell.

Kind regards, Al.
Al Chara is offline   Reply With Quote
Old Mar 18th, 2002, 01:52 PM   #8
Al Chara
MrExcel MVP
 
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
Default

Workbooks do not have to be open to read them, but remember a closed workbook can only return a value.
Al Chara is offline   Reply With Quote
Old Mar 18th, 2002, 03:32 PM   #9
kluitna
Board Regular
 
Join Date: Mar 2002
Posts: 75
Default

Al, that codes works thanks. one question, how would i modiofy that same code if I did not want to have any workbooks open except for the one I am using. also the code you provide works well. My problem is closing all the given workbooks after the data has been extracted. I replaced your h loop with a dim called source wich is linked to a series of cells with file names. I have tried every in the help section to makethis work. I just get code errors,

Again, thanks allot , been a big help. I have almost got this thing done.
kluitna is offline   Reply With Quote
Old Mar 18th, 2002, 03:46 PM   #10
Al Chara
MrExcel MVP
 
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
Default

Did you read my response here:

http://www.mrexcel.com/board/viewtop...2657&forum=2&1

Question: If you don't have the workbooks open, then when and from where do you get the names of the workbooks?


__________________
Kind regards,

Al Chara
Al Chara 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:14 PM.


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