#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 86
Default not urgent

I need a simple Boolean function that, given a range as an argument, will:

1. ignore blanks
2. ignore text cells
3. ignore cells containing formula
4. return 1 if any two cells in the range have the same value
5. return 0 if all the cells in the range have unique values

Thanks in Advance

--
Gary's Student
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default not urgent

will the function be used in the worksheet like

=Dups(A1:Z26)

or just as a vba function?

--
Regards,
Tom Ogilvy

"Gary's Student" wrote in message
...
I need a simple Boolean function that, given a range as an argument, will:

1. ignore blanks
2. ignore text cells
3. ignore cells containing formula
4. return 1 if any two cells in the range have the same value
5. return 0 if all the cells in the range have unique values

Thanks in Advance

--
Gary's Student



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 170
Default not urgent

simple? LOL

--
George Nicholson

Remove 'Junk' from return address.


"Gary's Student" wrote in message
...
I need a simple Boolean function that, given a range as an argument, will:

1. ignore blanks
2. ignore text cells
3. ignore cells containing formula
4. return 1 if any two cells in the range have the same value
5. return 0 if all the cells in the range have unique values

Thanks in Advance

--
Gary's Student



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 86
Default not urgent

Tom, I need the function in VBA. In spreadsheets I painfully and laboriously:

1. use a macro to copy the cells in range to an unused column
2. compare the used length of the column before and after applying filter
unique!

Strangely if I "columnize" the data, I can easily mark non-unique cells with
a pivot table and eliminate non-unique cells with advance filter. In VBA I
am not so clever; I dont need to count the non-uniques or delete them, just
determine if they are there..

--
Gary's Student


"Tom Ogilvy" wrote:

will the function be used in the worksheet like

=Dups(A1:Z26)

or just as a vba function?

--
Regards,
Tom Ogilvy

"Gary's Student" wrote in message
...
I need a simple Boolean function that, given a range as an argument, will:

1. ignore blanks
2. ignore text cells
3. ignore cells containing formula
4. return 1 if any two cells in the range have the same value
5. return 0 if all the cells in the range have unique values

Thanks in Advance

--
Gary's Student




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 230
Default not urgent

My attempt:

Function CheckCells(Rng As Range) As Integer
Dim cell As Range
Dim cell2 As Range
Dim RngNew As Range
Dim MyResult As Integer

Application.Volatile

For Each cell In Rng
If Not IsEmpty(cell) Then
If cell.PrefixCharacter = "" Then
If cell.NumberFormat < "@" Then
If cell.HasFormula = False Then
If RngNew Is Nothing Then
Set RngNew = cell
Else
Set RngNew = Union(RngNew, cell)
End If
End If
End If
End If
End If
Next cell

If RngNew Is Nothing Then
MyResult = -1
Else
For Each cell In RngNew
For Each cell2 In RngNew
If cell.Address < cell2.Address Then
If cell.Value = cell2.Value Then
MyResult = 1
GoTo ReportOut
End If
End If
Next cell2
Next cell
End If

ReportOut:
CheckCells = MyResult
End Function


"Gary's Student" wrote in message
...
I need a simple Boolean function that, given a range as an argument, will:

1. ignore blanks
2. ignore text cells
3. ignore cells containing formula
4. return 1 if any two cells in the range have the same value
5. return 0 if all the cells in the range have unique values

Thanks in Advance

--
Gary's Student





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 230
Default not urgent

I included a third result (-1) if no valid cells were comparable, but that
was taking license... sorry, easy for you to correct.


"William Benson" wrote in message
...
My attempt:

Function CheckCells(Rng As Range) As Integer
Dim cell As Range
Dim cell2 As Range
Dim RngNew As Range
Dim MyResult As Integer

Application.Volatile

For Each cell In Rng
If Not IsEmpty(cell) Then
If cell.PrefixCharacter = "" Then
If cell.NumberFormat < "@" Then
If cell.HasFormula = False Then
If RngNew Is Nothing Then
Set RngNew = cell
Else
Set RngNew = Union(RngNew, cell)
End If
End If
End If
End If
End If
Next cell

If RngNew Is Nothing Then
MyResult = -1
Else
For Each cell In RngNew
For Each cell2 In RngNew
If cell.Address < cell2.Address Then
If cell.Value = cell2.Value Then
MyResult = 1
GoTo ReportOut
End If
End If
Next cell2
Next cell
End If

ReportOut:
CheckCells = MyResult
End Function


"Gary's Student" wrote in message
...
I need a simple Boolean function that, given a range as an argument, will:

1. ignore blanks
2. ignore text cells
3. ignore cells containing formula
4. return 1 if any two cells in the range have the same value
5. return 0 if all the cells in the range have unique values

Thanks in Advance

--
Gary's Student





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 86
Default not urgent

William: Thank you very much. I'll start trying this out.

Thanks again.
--
Gary's Student


"William Benson" wrote:

My attempt:

Function CheckCells(Rng As Range) As Integer
Dim cell As Range
Dim cell2 As Range
Dim RngNew As Range
Dim MyResult As Integer

Application.Volatile

For Each cell In Rng
If Not IsEmpty(cell) Then
If cell.PrefixCharacter = "" Then
If cell.NumberFormat < "@" Then
If cell.HasFormula = False Then
If RngNew Is Nothing Then
Set RngNew = cell
Else
Set RngNew = Union(RngNew, cell)
End If
End If
End If
End If
End If
Next cell

If RngNew Is Nothing Then
MyResult = -1
Else
For Each cell In RngNew
For Each cell2 In RngNew
If cell.Address < cell2.Address Then
If cell.Value = cell2.Value Then
MyResult = 1
GoTo ReportOut
End If
End If
Next cell2
Next cell
End If

ReportOut:
CheckCells = MyResult
End Function


"Gary's Student" wrote in message
...
I need a simple Boolean function that, given a range as an argument, will:

1. ignore blanks
2. ignore text cells
3. ignore cells containing formula
4. return 1 if any two cells in the range have the same value
5. return 0 if all the cells in the range have unique values

Thanks in Advance

--
Gary's Student




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
IME MODE FOR EXCEL 2007 (URGENT URGENT) Stella Wong Excel Discussion (Misc queries) 1 August 23rd 08 11:16 PM
Urgent-Urgent VBA LOOP Jeff Excel Discussion (Misc queries) 0 October 6th 05 05:46 PM
HELP URGENT PLEASE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Juanjo[_2_] Excel Programming 0 February 5th 04 08:01 AM
Macro help urgent urgent Dave Peterson[_3_] Excel Programming 0 September 4th 03 03:59 PM
Macro help urgent urgent chandra Excel Programming 0 September 4th 03 03:50 PM


All times are GMT +1. The time now is 08:55 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"