Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Comander
 
Posts: n/a
Default comparing text cells

I want to compare two lists of comma delimited text items in two separate
cells and then determine which items are in one cell and not in the other,
and visa versa.

The available functions do not seem to support this, except EXACT, which
simply returns TRUE or FALSE. I want the items that represent the difference
between the cells.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Miguel Zapico
 
Posts: n/a
Default comparing text cells

You may use and UDF like this:

Function CompareStr(rng1 As Range, rng2 As Range)
Application.Volatile
Dim rng1Values, rng2Values, d, result, i
'The exists method of the dictionary object will be useful here
Set d = CreateObject("Scripting.Dictionary")
'Create arrays with the range values
rng1Values = Split(rng1.Value, ",")
rng2Values = Split(rng2.Value, ",")
'Loop over the values of the second array, and fill the dictionary
For i = 0 To UBound(rng2Values)
d.Add rng2Values(i), 1
Next
'Loop over the values of the first array, and check if they are in the
dictionary
For i = 0 To UBound(rng1Values)
'If the value is not present, add it to the result
If Not d.exists(rng1Values(i)) Then
result = result & "," & rng1Values(i)
End If
Next
'Present the result, if any
If Len(result) 0 Then
CompareStr = Right(result, Len(result) - 1)
Else
CompareStr = 0
End If
End Function

This function needs two cell references, and it will show the elements on
the first cell that are not in the second one. If you want to have the other
way, just swap the references.

Hope this helps,
Miguel.

"Comander" wrote:

I want to compare two lists of comma delimited text items in two separate
cells and then determine which items are in one cell and not in the other,
and visa versa.

The available functions do not seem to support this, except EXACT, which
simply returns TRUE or FALSE. I want the items that represent the difference
between the cells.

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Comander
 
Posts: n/a
Default comparing text cells

Thank you Miguel!

"Miguel Zapico" wrote:

You may use and UDF like this:

Function CompareStr(rng1 As Range, rng2 As Range)
Application.Volatile
Dim rng1Values, rng2Values, d, result, i
'The exists method of the dictionary object will be useful here
Set d = CreateObject("Scripting.Dictionary")
'Create arrays with the range values
rng1Values = Split(rng1.Value, ",")
rng2Values = Split(rng2.Value, ",")
'Loop over the values of the second array, and fill the dictionary
For i = 0 To UBound(rng2Values)
d.Add rng2Values(i), 1
Next
'Loop over the values of the first array, and check if they are in the
dictionary
For i = 0 To UBound(rng1Values)
'If the value is not present, add it to the result
If Not d.exists(rng1Values(i)) Then
result = result & "," & rng1Values(i)
End If
Next
'Present the result, if any
If Len(result) 0 Then
CompareStr = Right(result, Len(result) - 1)
Else
CompareStr = 0
End If
End Function

This function needs two cell references, and it will show the elements on
the first cell that are not in the second one. If you want to have the other
way, just swap the references.

Hope this helps,
Miguel.

"Comander" wrote:

I want to compare two lists of comma delimited text items in two separate
cells and then determine which items are in one cell and not in the other,
and visa versa.

The available functions do not seem to support this, except EXACT, which
simply returns TRUE or FALSE. I want the items that represent the difference
between the cells.

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
Summing cells that contain numbers and text Mango Excel Discussion (Misc queries) 10 May 13th 06 06:18 PM
merged cells into one text cell, size varies dependant on text dat Jazzylady825 Excel Discussion (Misc queries) 0 December 9th 05 08:26 PM
Comparing text strings in cells Andy Excel Discussion (Misc queries) 0 December 7th 05 04:17 PM
checking that cells have a value before the workbook will close kcdonaldson Excel Worksheet Functions 8 December 5th 05 04:57 PM
question about removing text from cells, leaving numbers JPN5804 Excel Discussion (Misc queries) 3 November 28th 05 05:55 PM


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