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

Below is a simple workbook that will help illustrate what I need help with.

Basically in the Q1 sheet, I have a min and a max feild. What I would like to do is have Excel automatically display the nameof the worksheet that has the MAX and MIN values. There is a comment in Q1 that gives a example. I know there are a few ways to do this, however I would like to beable to just have the worksheet name get displayed.

http://www3.sympatico.ca/daniel.demers2/Book1.xls

Daniel
  Reply With Quote
Old Feb 26th, 2002, 07:39 PM   #2
Guest
 
Posts: n/a
Default

Heya, this is Zenaph (Matt in RL). Try typing this in:

=IF(Jan!C3
  Reply With Quote
Old Feb 26th, 2002, 08:11 PM   #3
Guest
 
Posts: n/a
Default

heh, thanks for trying bro . However I need the "displayed month" to come from the worksheet name itself.

Example: if the lowest month came from the first sheet, "Jan" would be displayed, if I were to change the name on the worksheet to Oct, it would then display "Oct"...ect

I was afraid my explanation was not clear enough. I hope this is more clear.
I dont think its possible to do it in Excel, without messing around in VBA (where I just happen to be clueless...).
  Reply With Quote
Old Feb 26th, 2002, 09:32 PM   #4
Guest
 
Posts: n/a
Default

Do yourself a favor, list the cell (range in vba) that your comparison data can be found. The answer is around the corner........

Cheers!
  Reply With Quote
Old Feb 26th, 2002, 10:45 PM   #5
robfo0
Board Regular
 
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
Default

Here is a quick bit of code. I don't know if its the most efficient, theres probably some shortcut i dont know about, but here goes anyway

Sub SheetProfit()

Dim Profit As Long
Dim ProfitSheetName As String
Dim Min As Long
Dim MinSheet As String
Dim Max As Long
Dim MaxSheet As String

Application.ScreenUpdating = False

'Define Min as C3 on the first worksheet
Min = Worksheets(1).Range("C3")
MinSheet = Worksheets(1).Name

'Define Max as C3 on the first worksheet
Max = Worksheets(1).Range("C3")
MaxSheet = Worksheets(1).Name

'Loop through the worksheets
For Each xls In ActiveWorkbook.Worksheets
xls.Activate

'Stops the For loop when the loop gets to Sheet Q1
If ActiveSheet.Name = "Q1" Then
Exit For

Else

'Sets Profit equal to C3
Profit = Range("C3")
ProfitSheetName = ActiveSheet.Name

'If Min is greater than Profit in this sheet, redefine Min and catch the sheet name
If Min > Profit Then
Min = Profit
MinSheet = ProfitSheetName
End If

'If Max is less than Profit in this sheet, redefine Max and catch the sheet name
If Max < Profit Then
Max = Profit
MaxSheet = ProfitSheetName
End If
End If

'Go to the next sheet
Next xls

'Puts the values of Min and Max and the corresponding sheet names into their places in Q1
Worksheets("Q1").Range("C6") = Min
Worksheets("Q1").Range("D6") = MinSheet

Worksheets("Q1").Range("C7") = Max
Worksheets("Q1").Range("D7") = MaxSheet

Application.ScreenUpdating = True

End Sub


A few notes about the code. Sheet Q1 should be the last sheet in the workbook or it wont check the worksheets after that. Also, if 2 worksheets with a min or max value, the code will take only the first. you can change this if you want by making some condition or something if Max or Min = Profit. Hope this helps.

[ This Message was edited by: robfo0 on 2002-02-26 22:18 ]
robfo0 is offline   Reply With Quote
Old Feb 27th, 2002, 12:38 AM   #6
Guest
 
Posts: n/a
Default

works nicely

Thanks,
Daniel
  Reply With Quote
Old Feb 27th, 2002, 01:04 AM   #7
Guest
 
Posts: n/a
Default

Some alternative code (doesn't need sheet Q1 to be the last sheet :-

Dim ws As Worksheet, min As Range, max As Range, x%, y%
With Worksheets("Q1")
Set min = .[C6]
Set max = .[C7]
For Each ws In Worksheets
If ws.Name <> "Q1" Then
If x = 0 Then
If ws.[c3].Value = min Then
.[D6].Value = ws.Name
x = 1
End If
ElseIf y = 0 Then
If ws.[c3].Value = max Then
.[D7].Value = ws.Name
y = 1
End If
Else: Exit For
End If
End If
Next
End With
  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 06:42 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