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 26th, 2002, 02:59 PM   #1
AllenL
Board Regular
 
Join Date: Mar 2002
Posts: 67
Default

Hello
I am trying to create a combobox that has a list of data in a column that elimate the duplicated data and sort them.
I have a code(from the website) that creates very similar function I need. The only differences is that it uses listbox and not combobox. Then I try to modify it to combobox but I can't get it to work
The following is the code for the web:
Sub SortAndRemoveDupes()
Dim rListSort As Range, rOldList As Range
Dim strRowSource As String

'Clear Hidden sheet Column A ready for list
Sheet1.Range("A1", Sheet1.Range("A65536").End(xlUp)).Clear


'Set range variable to list we want
Set rOldList = Sheet2.Range("A1", Sheet2.Range("A65536").End(xlUp))

'Use AdvancedFilter to copy the list to Column A _
of the hidden sheet and remove all dupes
rOldList.AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=Sheet1.Cells(1, 1), Unique:=True

'Set range variable to the new non dupe list
Set rListSort = Sheet1.Range("A1", Sheet1.Range("A65536").End(xlUp))

With rListSort
'Sort the new non dupe list
.Sort Key1:=.Cells(2, 1), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End With

'Parse the address of the sorted unique items
strRowSource = Sheet1.Name & "!" & Sheet1.Range _
("A2", Sheet1.Range("A65536").End(xlUp)).Address

Sheet1.Range("A1") = "New Sorted Unique List"
With UserForm1.ListBox1
'Clear old ListBox RowSource
.RowSource = vbNullString
'Parse new one
.RowSource = strRowSource
End With

End Sub







This is the code after I modified:

Sub SortAndRemoveDupes()
Dim rListSort As Range, rOldList As Range
Dim strRowSource As String

'Clear Hidden sheet Column A ready for list



'Set range variable to list we want
Set rOldList = Columns(2)

'Use AdvancedFilter to copy the list to Column A _
of the hidden sheet and remove all dupes
rOldList.AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=Cells(1, 2), Unique:=True

'Set range variable to the new non dupe list
Set rListSort = Columns(2)

With rListSort
'Sort the new non dupe list
.Sort Key1:=.Cells(2, 2), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End With

'Parse the address of the sorted unique items
strRowSource = Columns(2).Address
MsgBox "StrRowSource" & strRowSource

With UserForm1.txtWeight

'Clear old ListBox RowSource
.RowSource = vbNullString
'Parse new one
.RowSource = strRowSource
'.AddItem = strRowSource

End With

End Sub


Can someone please help

Thanks in advance
AllenL is offline   Reply With Quote
Old Mar 26th, 2002, 04:11 PM   #2
Russell Hauf
MrExcel MVP
 
Russell Hauf's Avatar
 
Join Date: Feb 2002
Location: Portland, OR USA
Posts: 1,374
Default

What is the problem you are having?

Also, did you name your combo box txtWeight?

[ This Message was edited by: Russell Hauf on 2002-03-26 15:12 ]
Russell Hauf is offline   Reply With Quote
Old Mar 26th, 2002, 06:19 PM   #3
AllenL
Board Regular
 
Join Date: Mar 2002
Posts: 67
Default

Yes, I did name my combobox as txtWeight
I got an error on the following line
Sort Key1:=.Cells(2, 2), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

I can't figure out what cause this problem
Please help
Thanks in advance
AllenL is offline   Reply With Quote
Old Mar 26th, 2002, 07:15 PM   #4
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

Hi Allen

Did you download the example that goes with this?

You have made modifications to the code, but not allowed for this in other parts of the code! For example you have:

'Set range variable to list we want
Set rOldList = Columns(2)

'Use AdvancedFilter to copy the list to Column A _
of the hidden sheet and remove all dupes
rOldList.AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=Cells(1, 2), Unique:=True

I doubt this would work as you are trying to tell Advanced filter to Copy uniques to another range, but 'the range' is the range of the original list!



_________________
Kind Regards
Dave Hawley
OzGrid Business Applications
Microsoft Excel/VBA Training


[ This Message was edited by: Dave Hawley on 2002-03-26 18:17 ]
Dave Hawley is offline   Reply With Quote
Old Mar 27th, 2002, 06:19 AM   #5
AllenL
Board Regular
 
Join Date: Mar 2002
Posts: 67
Default

Hello Dave or Anyone
Is the line below

'Set range variable to list we want
Set rOldList = Sheet2.Range("A1", Sheet2.Range("A65536").End(xlUp))

the same as the line below?

Set rOldList = Columns(1)

Thanks in advance
AllenL is offline   Reply With Quote
Old Mar 27th, 2002, 06:34 AM   #6
AllenL
Board Regular
 
Join Date: Mar 2002
Posts: 67
Default

Hello
Can anyone tell me howcome the line below works
'Clear Hidden sheet Column A ready for list
Sheet1.Range("A1", Sheet1.Range("A65536").End(xlUp)).Clear

and the line below doesn't work. Aren't they the same???


Worksheets("Hidden").Range("A1", Sheet1.Range("A65536").End(xlUp)).Clear


Thanks
AllenL is offline   Reply With Quote
Old Mar 27th, 2002, 07:18 AM   #7
nisht
Board Regular
 
Join Date: Feb 2002
Location: Ahmedabad Gujarat
Posts: 303
Default

Allen,

Will you go through my example file..

16. Populating Combobox

here it has shown how to populate the comboboxes secondly to your code which removes duplicate..

Okay..

will you try my code and make necessay modifications.

you can get code for deleting duplicates or say extracting unique values from my website...

file nos is 5 ( it is a simple example) and other file which can interest you is file nos
22.


I hope if you study this two file will solve your problem

if you still have difficulty then write back to me

http://www.pexcel.com/download.htm

nishith desai
http://www.pexcel.com
nisht is offline   Reply With Quote
Old Mar 27th, 2002, 07:33 AM   #8
AllenL
Board Regular
 
Join Date: Mar 2002
Posts: 67
Default

Hello nisht
can you give me the VBA code passward for the file #5,16,22
Thanks
AllenL is offline   Reply With Quote
Old Mar 27th, 2002, 07:45 AM   #9
nisht
Board Regular
 
Join Date: Feb 2002
Location: Ahmedabad Gujarat
Posts: 303
Default

Allen,
please write me on

nisht@pexcel.com

i will sent you password.

and it is free

nishith desai
nisht is offline   Reply With Quote
Old Mar 27th, 2002, 08:15 AM   #10
AllenL
Board Regular
 
Join Date: Mar 2002
Posts: 67
Default

Hello Nisht
can you send me the password now
sorry I don't mean to rush you. I am just trying to finish this application before my boss come this afternoon
Thanks in advance
AllenL 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 10:20 AM.


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