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 9th, 2002, 09:38 AM   #1
waggy30
New Member
 
Join Date: Mar 2002
Location: England
Posts: 46
Default

Hello.
I am trying to write some code that deletes a name from a range. then re-assigns that name to another.

More specifically.

A B C
1 2 3
2 2 7
6 7 8
9 8 2

The range of cells above would change each time another macro is run. There may be more or less rows of data. So it could be:

A B C
1 2 3
2 2 7
6 7 8
9 8 2
8 9 4
5 6 4

What i want to do is rename the range each time to account for the new rows.

I have been trying for hours. can anyone help me?
waggy30 is offline   Reply With Quote
Old Mar 9th, 2002, 09:58 AM   #2
Barrie Davidson
MrExcel MVP
 
Barrie Davidson's Avatar
 
Join Date: Feb 2002
Location: Winnipeg
Posts: 2,330
Default

Use:

Range("A1", Range("C65536").End(xlUp).Address).Name = "Waggy30"


Regards,
__________________
Barrie Davidson

"You're only given a little spark of madness. You mustn't lose it." - Robin Williams
Barrie Davidson is offline   Reply With Quote
Old Mar 9th, 2002, 09:58 AM   #3
dk
MrExcel MVP
 
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
Default

Hi,

This code will add a named range for the current region. Say you had data in range A1:C3 and then you ran the macro it will create a named range AnyNameYouLike referring to that area. Now, if data is added to cell A4, the macro reran it will now refer to A1:C4.

Let me know if that isn't right,

Regards,
D

Code:
Sub CreateNamedRange()
ActiveWorkbook.Names.Add "AnyNameYouLike", "=" & ActiveSheet.Name & _
                "!" & Selection.CurrentRegion.Address, True
End Sub
dk is offline   Reply With Quote
Old Mar 9th, 2002, 10:20 AM   #4
Matanuska
New Member
 
Join Date: Feb 2002
Location: Houston, Texas
Posts: 28
Default

Have you considered using the OFFSET and COUNT functions to construct dynamic references that update automatically as data are added?

This sounds like it might do what you want.
Matanuska is offline   Reply With Quote
Old Mar 9th, 2002, 10:22 AM   #5
Aladin Akyurek
MrExcel MVP
 
Aladin Akyurek's Avatar
 
Join Date: Feb 2002
Location: The Hague
Posts: 50,317
Default

Quote:
On 2002-03-09 08:38, waggy30 wrote:
Hello.
I am trying to write some code that deletes a name from a range. then re-assigns that name to another.

More specifically.

A B C
1 2 3
2 2 7
6 7 8
9 8 2

The range of cells above would change each time another macro is run. There may be more or less rows of data. So it could be:

A B C
1 2 3
2 2 7
6 7 8
9 8 2
8 9 4
5 6 4

What i want to do is rename the range each time to account for the new rows.

I have been trying for hours. can anyone help me?
Another way to achieve what you want.

Lets say that A2:C7 in Sheet1 houses your first sample data (I suppose A1:C1 will house descriptive labels).


Activate Insert|Name|Define.

Enter 'EndRow' in the "Names in Workbook" box.

Enter the following formula in the "Refers to" box:

=OFFSET(Sheet1!$A$2,0,0,MATCH(9.99999999999999E+307,Sheet1!$A:$A),1)

I assume here that data in column A in Sheet1 is of numeric type (numbers or dates). If this is not the case, replace A with the column identifier of another column which meets the condition of being of numeric type.

Click Add.

While still in the Define Name window,

enter SDATA (from Source Data) in the Names in Workbook box;

enter as formula in the Refers to box:

=OFFSET(Sheet1!$A$2,0,0,EndRow-1,3)

Click OK.

-1 in the EndRow-1 bit "strips off" the row that contains labels from the definition of the range.

Try as an exercise:

=VLOOKUP(2,SDATA,3,0)

Try also adding more rows of data or deleting rows from Sheet1.


[ This Message was edited by: Aladin Akyurek on 2002-03-11 08:46 ]
Aladin Akyurek is offline   Reply With Quote
Old Mar 9th, 2002, 11:03 AM   #6
Guest
 
Posts: n/a
Default

You can also define a dynamic range, which will change as you enter data.

If you go to Insert-Name-Define, type in a name for the range, the type the following formula in the Refers To box:

=OFFSET(Sheet2!$A$1,,,COUNTA(Sheet2!$A:$A),COUNTA(Sheet2!
$1:$1))

Note: if you data does not start in cell A1, then you will have to adjust this. Let me know if it does not.

Hope this helps,

Russell
  Reply With Quote
Old Mar 9th, 2002, 11:04 AM   #7
Russell Hauf
MrExcel MVP
 
Russell Hauf's Avatar
 
Join Date: Feb 2002
Location: Portland, OR USA
Posts: 1,374
Default

Sorry, the last message was from me.
Russell Hauf is offline   Reply With Quote
Old Mar 9th, 2002, 12:23 PM   #8
Paul B
Board Regular
 
Join Date: Feb 2002
Location: Georgia USA
Posts: 544
Default

Russell,I am trying to use your formula for a name range it works fine for column a I need it for column C, I thought I could just change the numbers on the end but that is not working for me. Also is there any way to paste in the refers to box? Thanks
Paul B is offline   Reply With Quote
Old Mar 9th, 2002, 12:25 PM   #9
waggy30
New Member
 
Join Date: Mar 2002
Location: England
Posts: 46
Default

No, Russell the first row of the actual data is F25:H25. Would it still work if i want multiple columns?

waggy30 is offline   Reply With Quote
Old Mar 9th, 2002, 01:46 PM   #10
waggy30
New Member
 
Join Date: Mar 2002
Location: England
Posts: 46
Default

Barry, can you explain what your code is doing. So i can adapt it to my real situation (the data isn't in the cells i used an example). I tried your code with the example I gave and it worked, but i can't adapt it.

Thanks
waggy30 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