Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Collection from Range, tag cells on error

Hello,
I am using a standard piece of code taken from this newgroup to get a unique
collection of items taken from a range.

Dim AllCells As Range, Cell As Range

Dim NoDupes As New Collection

Lstcll = Application.WorksheetFunction.CountA(ActiveSheet.R ange("A:A"))

Set AllCells = ActiveSheet.Range("A2:A" & Lstcll)

On Error Resume Next

For Each Cell In AllCells

NoDupes.Add Cell.Value, CStr(Cell.Value)

Next Cell

I understand the premise of using this because Excel generates an error when
trying to add a duplicate to the collection and will not add it. But how
can i make Excel write something like "if is error(NoDupes.Add Cell.value)
then
Cell.offset(0,9).value = "Delete Me"

Thank you.





  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Collection from Range, tag cells on error

One way:

Option Explicit
Sub testme()
Dim AllCells As Range
Dim Cell As Range
Dim NoDupes As Collection
Dim LstCll As Long

Set NoDupes = New Collection

LstCll = Application.WorksheetFunction.CountA(ActiveSheet.R ange("A:A"))

Set AllCells = ActiveSheet.Range("A2:A" & LstCll)

On Error Resume Next
For Each Cell In AllCells.Cells
NoDupes.Add Cell.Value, CStr(Cell.Value)
If Err.Number < 0 Then
Cell.Offset(0, 1).Value = "Delete me"
Err.Clear
End If
Next Cell
On Error GoTo 0

End Sub


nowon wrote:

Hello,
I am using a standard piece of code taken from this newgroup to get a unique
collection of items taken from a range.

Dim AllCells As Range, Cell As Range

Dim NoDupes As New Collection

Lstcll = Application.WorksheetFunction.CountA(ActiveSheet.R ange("A:A"))

Set AllCells = ActiveSheet.Range("A2:A" & Lstcll)

On Error Resume Next

For Each Cell In AllCells

NoDupes.Add Cell.Value, CStr(Cell.Value)

Next Cell

I understand the premise of using this because Excel generates an error when
trying to add a duplicate to the collection and will not add it. But how
can i make Excel write something like "if is error(NoDupes.Add Cell.value)
then
Cell.offset(0,9).value = "Delete Me"

Thank you.


--

Dave Peterson
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
Can't trap error when checking for keys not in Collection BW Excel Programming 6 August 3rd 05 09:15 PM
Error with passing collection as parameter McManCSU[_17_] Excel Programming 3 August 1st 05 06:19 PM
Range collection Ernst Guckel[_4_] Excel Programming 4 May 1st 05 08:01 PM
efficiency qn: search collection or use on error? noel mc Excel Programming 6 November 10th 04 06:19 PM
Runtime error with the sheet collection, which was not there in 20 Laks Excel Programming 1 June 18th 04 11:55 AM


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

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

About Us

"It's about Microsoft Excel"