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 Feb 17th, 2002, 05:16 PM   #1
Guest
 
Posts: n/a
Default

Hello All.

I was wondering if it is possible to automatically define names based on a formula.

For example if cell a1 = yes, name a1 "YES1". if cell a5 = yes, name a5 "YES2". Etc...

I hope the above is clear enough to understand. Thankyou all in advance for your help.
  Reply With Quote
Old Feb 19th, 2002, 03:36 PM   #2
Damon Ostrander
MrExcel MVP
 
Damon Ostrander's Avatar
 
Join Date: Feb 2002
Location: Denver, Colorado USA
Posts: 4,014
Default

Hi Anonymous,

No, I don't believe a worksheet formula or function can do this because formulas are not allowed to change anything other than the contents of the cell containing the formula, but especially not properties of other cells.

What you describe could very easily be accomplished via a macro, however, and by triggering it from a worksheet Change event it would be made to work with exactly the functionality you describe. Let me know if you wish to explore this further.

__________________
Keep Excelling.

Damon

VBAexpert Excel Consulting
(My other life: http://damonostrander.com )
Damon Ostrander is offline   Reply With Quote
Old Feb 20th, 2002, 05:31 AM   #3
Guest
 
Posts: n/a
Default

Hi Damon,

Thanks for your response. Sorry it took me a little while to reply, had a very busy couple of days.

I would be very interested in achieving this through the use of a macro.

Unfortunately my macro skills are not at the level they should be!!

Here is an example of what I would like to do.

A
1
2 Yes
3
4
5 No
6
7 Yes

Cell A2 I want to define as Answer1, Cell A5 as Answer2 and Cell A7 as Answer3. The sheet could have upwards of 200 names to define over 6000 rows so going through each becomes a little cumbersome.

Any help would be greatly appreciated.

Thankyou again Damon,
Sam

  Reply With Quote
Old Feb 21st, 2002, 05:10 PM   #4
Guest
 
Posts: n/a
Default

Hi again Sam,

Here's a little macro that I believe does what you want:

Option Base 1

Private Sub YesNames()
Static Index As Long
Dim Addr As Variant
Dim Cell As Range
Dim i As Integer
Addr = Array("a2", "a5", "a7")
For i = 1 To UBound(Addr)
Set Cell = Range(Addr(i))
If UCase(Cell.Value) = "YES" Then
Index = Index + 1
Cell.Name = "Yes" & Index
End If
Next i
End Sub

As you can see, it only does the three cells you mentioned, and skips cells containing "No". You can increase the size of the list to about 30 entries with the Array statment, but beyond that you would have to set the array elements, e.g.,

Dim Addr(100) As String

Addr(1) = "a3"
Addr(2) = "a2"
Addr(3) = "a7"
.
.
.
Addr(99) = "a304"
Addr(100) = "a333"

I hope I interpreted you problem correctly.
  Reply With Quote
Old Feb 21st, 2002, 05:41 PM   #5
Guest
 
Posts: n/a
Default

Thanks mate. I'll plug it in and give it a go and let you know how it works.

Sam
  Reply With Quote
Old Feb 21st, 2002, 05:42 PM   #6
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

I'll throw the following into the mix, names cells in column B (if you want column A, see next post (assuming your answers are in column B (change the range selection if not))):

Sub Nameit()
i = 1
Application.ScreenUpdating = False
Range("b1:b6000").Select
For Each Cell In Selection
If ActiveCell <> "" Then
ActiveWorkbook.Names.Add Name:="Answer" & i, RefersToR1C1:=ActiveCell
i = i + 1
End If
ActiveCell.Offset(1, 0).Select
Next Cell
Range("a1").Select
Application.ScreenUpdating = True
End Sub


Cheers,
Nate

[ This Message was edited by: NateO on 2002-02-21 17:36 ]
NateO is offline   Reply With Quote
Old Feb 21st, 2002, 06:33 PM   #7
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

I guess if had values in column b but wanted to name the cells in column a (which look like row numbers), you could use the following:

Sub Nameit2()
i = 1
Application.ScreenUpdating = False
Range("b1:b6000").Select
For Each Cell In Selection
If ActiveCell <> "" Then
ActiveWorkbook.Names.Add Name:="Answer" & i, RefersToR1C1:=ActiveCell.Offset(0, -1)
i = i + 1
End If
ActiveCell.Offset(1, 0).Select
Next Cell
Range("a1").Select
Application.ScreenUpdating = True
End Sub

Cheers,

Nate
__________________
Regards,
Nate Oliver
Microsoft Excel MVP
Nate's Excel Blog
NateO is offline   Reply With Quote
Old Feb 22nd, 2002, 12:15 AM   #8
Guest
 
Posts: n/a
Default

Thanks NateO,

Looks perfect. I'll let you know.

Do you guys realise how much time you save everyone who has questions here! Excellent work.

  Reply With Quote
Old Feb 22nd, 2002, 04:17 AM   #9
Guest
 
Posts: n/a
Default

Yep looked and was perfect.

You have saved me an enormous amount of time. Thankyou very much NateO.

Sam
  Reply With Quote
Old Feb 22nd, 2002, 12:50 PM   #10
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

You're welcome Sam.

Cheers, Nate
__________________
Regards,
Nate Oliver
Microsoft Excel MVP
Nate's Excel Blog
NateO 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 05:20 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