#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 158
Default Userform

Dear all,

Please advise what's wrong with the code below to remove duplicates from a
list to a listbox in an userform. A warning dialog box stated "variable not
defined" to a word "Item"

Sub RemoveDuplicates1()
Dim AllCells As Range, Cell As Range
Dim NoDupes As New Collection

On Error Resume Next
For Each Cell In Range("A1:A54")
NoDupes.Add Cell.Value, CStr(Cell.Value)
Next Cell
On Error GoTo 0

For Each Item In NoDupes
UserForm1.ListBox1.AddItem Item
Next Item

UserForm1.Show
Unload UserForm1
End Sub

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,489
Default Userform

Hi,

You have Option Explicit set at the top of your code module, which is
good. This requires you to declare ALL variables.

You have not declare the variable Item.

Cheers
Andy

Freshman wrote:
Dear all,

Please advise what's wrong with the code below to remove duplicates from a
list to a listbox in an userform. A warning dialog box stated "variable not
defined" to a word "Item"

Sub RemoveDuplicates1()
Dim AllCells As Range, Cell As Range
Dim NoDupes As New Collection

On Error Resume Next
For Each Cell In Range("A1:A54")
NoDupes.Add Cell.Value, CStr(Cell.Value)
Next Cell
On Error GoTo 0

For Each Item In NoDupes
UserForm1.ListBox1.AddItem Item
Next Item

UserForm1.Show
Unload UserForm1
End Sub

Thanks.


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,593
Default Userform

Item is not a good word for a variable either. I haven't tested if it is a
problem, but as it is part of VBA syntax it should be avoided.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Andy Pope" wrote in message
...
Hi,

You have Option Explicit set at the top of your code module, which is
good. This requires you to declare ALL variables.

You have not declare the variable Item.

Cheers
Andy

Freshman wrote:
Dear all,

Please advise what's wrong with the code below to remove duplicates from

a
list to a listbox in an userform. A warning dialog box stated "variable

not
defined" to a word "Item"

Sub RemoveDuplicates1()
Dim AllCells As Range, Cell As Range
Dim NoDupes As New Collection

On Error Resume Next
For Each Cell In Range("A1:A54")
NoDupes.Add Cell.Value, CStr(Cell.Value)
Next Cell
On Error GoTo 0

For Each Item In NoDupes
UserForm1.ListBox1.AddItem Item
Next Item

UserForm1.Show
Unload UserForm1
End Sub

Thanks.


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info



  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,489
Default Userform

Hi Bob,

Yes your right, it is a bad choice but it does work.

Cheers
Andy

Bob Phillips wrote:
Item is not a good word for a variable either. I haven't tested if it is a
problem, but as it is part of VBA syntax it should be avoided.


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,593
Default Userform

Many do Andy, but being part of the syntax means that we cannot guarantee
they always will.

Bob

"Andy Pope" wrote in message
...
Hi Bob,

Yes your right, it is a bad choice but it does work.

Cheers
Andy

Bob Phillips wrote:
Item is not a good word for a variable either. I haven't tested if it is

a
problem, but as it is part of VBA syntax it should be avoided.


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
UserForm background was dotted, now plain? dk_ Excel Discussion (Misc queries) 0 November 6th 06 01:53 AM
coping and create new userform ASU Excel Discussion (Misc queries) 0 July 25th 06 12:54 PM
Userform and variables Jeff Excel Discussion (Misc queries) 1 May 24th 06 02:20 PM
Cell Content from UserForm Not Retained D.Parker Excel Discussion (Misc queries) 3 April 27th 05 04:56 PM
How can I run a macro in the background whilst a UserForm is visib cdb Excel Discussion (Misc queries) 3 February 10th 05 06:58 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"