PC Review


Reply
Thread Tools Rate Thread

Deleting Duplicate items in a ListBox

 
 
=?Utf-8?B?Q0xhbWFy?=
Guest
Posts: n/a
 
      6th Jun 2006
I have a Listbox in Excel and I am trying to loop through and delete the
duplicate entries. How can I do this using VBA

Thanks
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      6th Jun 2006
Take a look at John Walkenbach's routine to fill a listbox with unique values:
http://j-walk.com/ss/excel/tips/tip47.htm



CLamar wrote:
>
> I have a Listbox in Excel and I am trying to loop through and delete the
> duplicate entries. How can I do this using VBA
>
> Thanks


--

Dave Peterson
 
Reply With Quote
 
=?Utf-8?B?Q0xhbWFy?=
Guest
Posts: n/a
 
      6th Jun 2006
Thanks for the quick response. Now my question is how do i find the end of a
Range without hardcoding it. For example I have:
For Each Cell In Range("A2:","") I am trying to put in a null value to
locate the end of the column, but its not working

"Dave Peterson" wrote:

> Take a look at John Walkenbach's routine to fill a listbox with unique values:
> http://j-walk.com/ss/excel/tips/tip47.htm
>
>
>
> CLamar wrote:
> >
> > I have a Listbox in Excel and I am trying to loop through and delete the
> > duplicate entries. How can I do this using VBA
> >
> > Thanks

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      6th Jun 2006
Dim myCell as range
with activesheet
for each myCell in .range("a2",.cells(.rows.count,"A").end(xlup)).cells
...

It's the equivalent of starting in A65536 and hitting the End key followed by
the up arrow.

======
If you need it for other stuff:

Dim LastRow as long
dim myCell as range
with activesheet
lastrow = .cells(.rows.count,"A").end(xlup).row
for each mycell in .range("a2:A" & lastrow).cells)
....




CLamar wrote:
>
> Thanks for the quick response. Now my question is how do i find the end of a
> Range without hardcoding it. For example I have:
> For Each Cell In Range("A2:","") I am trying to put in a null value to
> locate the end of the column, but its not working
>
> "Dave Peterson" wrote:
>
> > Take a look at John Walkenbach's routine to fill a listbox with unique values:
> > http://j-walk.com/ss/excel/tips/tip47.htm
> >
> >
> >
> > CLamar wrote:
> > >
> > > I have a Listbox in Excel and I am trying to loop through and delete the
> > > duplicate entries. How can I do this using VBA
> > >
> > > Thanks

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      6th Jun 2006
Typo in that last section...

Dim LastRow as long
dim myCell as range
with activesheet
lastrow = .cells(.rows.count,"A").end(xlup).row
for each mycell in .range("a2:A" & lastrow).cells
....

(I removed that final closing paren.)

CLamar wrote:
>
> Thanks for the quick response. Now my question is how do i find the end of a
> Range without hardcoding it. For example I have:
> For Each Cell In Range("A2:","") I am trying to put in a null value to
> locate the end of the column, but its not working
>
> "Dave Peterson" wrote:
>
> > Take a look at John Walkenbach's routine to fill a listbox with unique values:
> > http://j-walk.com/ss/excel/tips/tip47.htm
> >
> >
> >
> > CLamar wrote:
> > >
> > > I have a Listbox in Excel and I am trying to loop through and delete the
> > > duplicate entries. How can I do this using VBA
> > >
> > > Thanks

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
=?Utf-8?B?Q0xhbWFy?=
Guest
Posts: n/a
 
      6th Jun 2006
Once again thanks for the quick response, but now its giving me a runtime
error 457 "this key is already associated with an element of this collection"

"Dave Peterson" wrote:

> Typo in that last section...
>
> Dim LastRow as long
> dim myCell as range
> with activesheet
> lastrow = .cells(.rows.count,"A").end(xlup).row
> for each mycell in .range("a2:A" & lastrow).cells
> ....
>
> (I removed that final closing paren.)
>
> CLamar wrote:
> >
> > Thanks for the quick response. Now my question is how do i find the end of a
> > Range without hardcoding it. For example I have:
> > For Each Cell In Range("A2:","") I am trying to put in a null value to
> > locate the end of the column, but its not working
> >
> > "Dave Peterson" wrote:
> >
> > > Take a look at John Walkenbach's routine to fill a listbox with unique values:
> > > http://j-walk.com/ss/excel/tips/tip47.htm
> > >
> > >
> > >
> > > CLamar wrote:
> > > >
> > > > I have a Listbox in Excel and I am trying to loop through and delete the
> > > > duplicate entries. How can I do this using VBA
> > > >
> > > > Thanks
> > >
> > > --
> > >
> > > Dave Peterson
> > >

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      6th Jun 2006
You didn't copy all John's code into your module.

John has an "on error resume next" line that you dropped.

CLamar wrote:
>
> Once again thanks for the quick response, but now its giving me a runtime
> error 457 "this key is already associated with an element of this collection"
>
> "Dave Peterson" wrote:
>
> > Typo in that last section...
> >
> > Dim LastRow as long
> > dim myCell as range
> > with activesheet
> > lastrow = .cells(.rows.count,"A").end(xlup).row
> > for each mycell in .range("a2:A" & lastrow).cells
> > ....
> >
> > (I removed that final closing paren.)
> >
> > CLamar wrote:
> > >
> > > Thanks for the quick response. Now my question is how do i find the end of a
> > > Range without hardcoding it. For example I have:
> > > For Each Cell In Range("A2:","") I am trying to put in a null value to
> > > locate the end of the column, but its not working
> > >
> > > "Dave Peterson" wrote:
> > >
> > > > Take a look at John Walkenbach's routine to fill a listbox with unique values:
> > > > http://j-walk.com/ss/excel/tips/tip47.htm
> > > >
> > > >
> > > >
> > > > CLamar wrote:
> > > > >
> > > > > I have a Listbox in Excel and I am trying to loop through and delete the
> > > > > duplicate entries. How can I do this using VBA
> > > > >
> > > > > Thanks
> > > >
> > > > --
> > > >
> > > > Dave Peterson
> > > >

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
=?Utf-8?B?Q0xhbWFy?=
Guest
Posts: n/a
 
      8th Jun 2006
How would you locate the last cell in a column using the R1C1 method?

"Dave Peterson" wrote:

> You didn't copy all John's code into your module.
>
> John has an "on error resume next" line that you dropped.
>
> CLamar wrote:
> >
> > Once again thanks for the quick response, but now its giving me a runtime
> > error 457 "this key is already associated with an element of this collection"
> >
> > "Dave Peterson" wrote:
> >
> > > Typo in that last section...
> > >
> > > Dim LastRow as long
> > > dim myCell as range
> > > with activesheet
> > > lastrow = .cells(.rows.count,"A").end(xlup).row
> > > for each mycell in .range("a2:A" & lastrow).cells
> > > ....
> > >
> > > (I removed that final closing paren.)
> > >
> > > CLamar wrote:
> > > >
> > > > Thanks for the quick response. Now my question is how do i find the end of a
> > > > Range without hardcoding it. For example I have:
> > > > For Each Cell In Range("A2:","") I am trying to put in a null value to
> > > > locate the end of the column, but its not working
> > > >
> > > > "Dave Peterson" wrote:
> > > >
> > > > > Take a look at John Walkenbach's routine to fill a listbox with unique values:
> > > > > http://j-walk.com/ss/excel/tips/tip47.htm
> > > > >
> > > > >
> > > > >
> > > > > CLamar wrote:
> > > > > >
> > > > > > I have a Listbox in Excel and I am trying to loop through and delete the
> > > > > > duplicate entries. How can I do this using VBA
> > > > > >
> > > > > > Thanks
> > > > >
> > > > > --
> > > > >
> > > > > Dave Peterson
> > > > >
> > >
> > > --
> > >
> > > Dave Peterson
> > >

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      8th Jun 2006
R1C1 is used with formulas in the worksheet--not to refer to addresses in code.

But you could use .cells() and refer to rows and columns:

lastrow = .cells(.rows.count,1).end(xlup).row

The 1 represents column A (the first column).


..cells(x,y)
x = row
y = column




CLamar wrote:
>
> How would you locate the last cell in a column using the R1C1 method?
>
> "Dave Peterson" wrote:
>
> > You didn't copy all John's code into your module.
> >
> > John has an "on error resume next" line that you dropped.
> >
> > CLamar wrote:
> > >
> > > Once again thanks for the quick response, but now its giving me a runtime
> > > error 457 "this key is already associated with an element of this collection"
> > >
> > > "Dave Peterson" wrote:
> > >
> > > > Typo in that last section...
> > > >
> > > > Dim LastRow as long
> > > > dim myCell as range
> > > > with activesheet
> > > > lastrow = .cells(.rows.count,"A").end(xlup).row
> > > > for each mycell in .range("a2:A" & lastrow).cells
> > > > ....
> > > >
> > > > (I removed that final closing paren.)
> > > >
> > > > CLamar wrote:
> > > > >
> > > > > Thanks for the quick response. Now my question is how do i find the end of a
> > > > > Range without hardcoding it. For example I have:
> > > > > For Each Cell In Range("A2:","") I am trying to put in a null value to
> > > > > locate the end of the column, but its not working
> > > > >
> > > > > "Dave Peterson" wrote:
> > > > >
> > > > > > Take a look at John Walkenbach's routine to fill a listbox with unique values:
> > > > > > http://j-walk.com/ss/excel/tips/tip47.htm
> > > > > >
> > > > > >
> > > > > >
> > > > > > CLamar wrote:
> > > > > > >
> > > > > > > I have a Listbox in Excel and I am trying to loop through and delete the
> > > > > > > duplicate entries. How can I do this using VBA
> > > > > > >
> > > > > > > Thanks
> > > > > >
> > > > > > --
> > > > > >
> > > > > > Dave Peterson
> > > > > >
> > > >
> > > > --
> > > >
> > > > Dave Peterson
> > > >

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
=?Utf-8?B?Q0xhbWFy?=
Guest
Posts: n/a
 
      8th Jun 2006
Okay I understand that, but how am i supposed to find the last cell in a
column so that i can use it in a series to create a plot without hardcoding
it.

thanks

"Dave Peterson" wrote:

> R1C1 is used with formulas in the worksheet--not to refer to addresses in code.
>
> But you could use .cells() and refer to rows and columns:
>
> lastrow = .cells(.rows.count,1).end(xlup).row
>
> The 1 represents column A (the first column).
>
>
> ..cells(x,y)
> x = row
> y = column
>
>
>
>
> CLamar wrote:
> >
> > How would you locate the last cell in a column using the R1C1 method?
> >
> > "Dave Peterson" wrote:
> >
> > > You didn't copy all John's code into your module.
> > >
> > > John has an "on error resume next" line that you dropped.
> > >
> > > CLamar wrote:
> > > >
> > > > Once again thanks for the quick response, but now its giving me a runtime
> > > > error 457 "this key is already associated with an element of this collection"
> > > >
> > > > "Dave Peterson" wrote:
> > > >
> > > > > Typo in that last section...
> > > > >
> > > > > Dim LastRow as long
> > > > > dim myCell as range
> > > > > with activesheet
> > > > > lastrow = .cells(.rows.count,"A").end(xlup).row
> > > > > for each mycell in .range("a2:A" & lastrow).cells
> > > > > ....
> > > > >
> > > > > (I removed that final closing paren.)
> > > > >
> > > > > CLamar wrote:
> > > > > >
> > > > > > Thanks for the quick response. Now my question is how do i find the end of a
> > > > > > Range without hardcoding it. For example I have:
> > > > > > For Each Cell In Range("A2:","") I am trying to put in a null value to
> > > > > > locate the end of the column, but its not working
> > > > > >
> > > > > > "Dave Peterson" wrote:
> > > > > >
> > > > > > > Take a look at John Walkenbach's routine to fill a listbox with unique values:
> > > > > > > http://j-walk.com/ss/excel/tips/tip47.htm
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > CLamar wrote:
> > > > > > > >
> > > > > > > > I have a Listbox in Excel and I am trying to loop through and delete the
> > > > > > > > duplicate entries. How can I do this using VBA
> > > > > > > >
> > > > > > > > Thanks
> > > > > > >
> > > > > > > --
> > > > > > >
> > > > > > > Dave Peterson
> > > > > > >
> > > > >
> > > > > --
> > > > >
> > > > > Dave Peterson
> > > > >
> > >
> > > --
> > >
> > > Dave Peterson
> > >

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting duplicate items in Calendar" BobG Microsoft Outlook Calendar 1 8th Mar 2009 07:50 PM
Re: Listbox containing duplicate items - correct selection not maintained on postback? Adam Clauss Microsoft ASP .NET 2 8th Sep 2005 07:59 PM
Re: Listbox containing duplicate items - correct selection not maintained on postback? Damien Microsoft ASP .NET 1 8th Sep 2005 03:51 PM
Eleminate duplicate items in a listbox mamatha Microsoft VB .NET 5 27th Sep 2004 10:41 AM
Re: Adding/Deleting items in a ListBox Wayne Morgan Microsoft Access Form Coding 0 25th Sep 2003 01:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:11 PM.