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 20th, 2002, 08:31 AM   #1
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

I have a list of names (Names) in sheet 1 Column A that I need to be able to paste onto a new sheet. Most names appear more than once.

The thing is I need to paste each name only once. (Lets call this new list NamesOnce) How can I do this with a macro?

On top of that, each name has a value associated with it, let call that SALES. Is there anyway to have next to the NamesOnce list the Maximum Value associated with a certain name?

E.g

Names Sales
Lisa 4
Bob 4
Josh 1
Paula 7
Lisa 5
Bob 2
Bob 6
Josh 10
Paula 8

I need to have this on a new sheet

Names Max
Lisa 5
Bob 6
Josh 10
Paula 8

Can I do this?
Cosmos75 is offline   Reply With Quote
Old Mar 20th, 2002, 08:35 AM   #2
paelinck
Board Regular
 
Join Date: Mar 2002
Location: Leiden, The Netherlands
Posts: 68
Default

A Pivot Table can do exactly that: make a unique list of names and add the maximum (or sum or minimum or average) of the corresponding values. So don't use a macro for this. See Excel Help for the use of Pivot Tables.

Marc
paelinck is offline   Reply With Quote
Old Mar 20th, 2002, 08:55 AM   #3
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

Hi

Pivot Table would be good.


But here's a macro anyway.

Sub DoIt()
Range("A1", Range("A65536").End(xlUp)).AdvancedFilter _
Action:=xlFilterInPlace, Unique:=True

Range("A1", Range("B65536").End(xlUp)).SpecialCells _
(xlCellTypeVisible).Copy Destination:=Sheets("Sheet1").Range("A1")

ActiveSheet.ShowAllData
End Sub

Dave Hawley is offline   Reply With Quote
Old Mar 20th, 2002, 11:43 AM   #4
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

Dave,

That works, but it doesn't choose the maximum value for each person, just the first one. This list is not sorted and if there is a way I would rather not sort if.



Maybe have an array formula with the ranges defined using End(xlUp). After pasting the Names only once.

Like

Range1 = Range("A1",Range("A65536").End(xlUp).Address)
Range2 = Range("B1",Range("B65536").End(xlUp).Address)

Sheets("Target").Select
Range("B1").Select
Selection.FormulaArray = "=MAX(IF(Range1=A2,Range2))"

It's A2 since A2 would have "Name" in it.

Probably have to first count the number of unique names on Target sheet, loop through A2 until the end. Maybe count the number of unique names using select Range of Target Sheet ColumnA, then RowCount.Selection?

Is there an alternative to looping?
Cosmos75 is offline   Reply With Quote
Old Mar 20th, 2002, 01:45 PM   #5
Joe Was
MrExcel MVP
 
Joe Was's Avatar
 
Join Date: Feb 2002
Location: Central Florida, USA
Posts: 7,541
Default

Sub Find_Names()

'Finds all the unique names, count the number of times each name is listed and give the total value of each name.
'Data is on Sheet2: Names(G), Values(I), Results are listed on Sheet3: Names(H), Count(I) & Values(J).
Application.ScreenUpdating = False

'Find unique names on Sheet2(G), col(7) & list on Sheet3(H).
With Intersect(ActiveSheet.Columns(7), ActiveSheet.UsedRange)
.AdvancedFilter Action:=xlFilterInPlace, Unique:=True
.SpecialCells(xlCellTypeVisible).Copy Destination:=Worksheets("Sheet3").Range("H1")
ActiveSheet.ShowAllData
End With

'Sort unique names on sheet3(H).
Sheets("Sheet3").Select
Columns(8).Sort Key1:=Range("H1")

'Count occurrences of names on Sheet2(G), col(7).
'List the number of times each unique name occurred on Sheet2(G), next to the list on sheet3(I).
With Worksheets("Sheet3")
.Range("I1").Formula = "=CountIf(Sheet2!" & Intersect(Sheet2.Columns(7), Sheet2.UsedRange).Address & ",H1)"
.Range("I1:I" & .Range("H1").End(xlDown).Row).FillDown
End With

'Sum values by name on sheet2(I).
'List the sum of values for each unique name occurred on Sheet2: Name(G), Value(I),
'on sheet3: Name(H) & Value(J).
With Worksheets("Sheet3")
.Range("J1").Formula = "=SumIf(Sheet2!" & Intersect(Sheet2.Columns(7), Sheet2.UsedRange).Address & ",H1,Sheet2!I$1:I$" & Worksheets("Sheet3").Range("H1").End(xlDown).Row & ")"
.Range("J1:J" & .Range("H1").End(xlDown).Row).FillDown
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True

End Sub

The results are: Name, number of sales, Total value of sales. All as unique names list, extracted from the master (non-unique) list of data. Hope this helps. JSW
Joe Was is offline   Reply With Quote
Old Mar 20th, 2002, 02:59 PM   #6
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

Joe Was,

Thanks for the code, it'll come in handy for another part of my workbook, but what I was hoping to show the maximum value of sales for each person and not the sum of sales for each person.

THANKS FOR THE CODE!!
Cosmos75 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 03:31 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