PDA

Click to See Complete Forum and Search --> : [RESOLVED] Cell comparisons


waldermort
Mar 9th, 2006, 08:30 AM
I have have finally got my code up and running for the most part. I am comparing the values of cells, which contain strings. My function works to a degree but it is case dependant. How do you implement a non-case sensetive comparison of two strings in vb?
Sub RemoveDuplicates()
Dim iListCount As Integer
Dim iCtr As Integer

iListCount = xlSheet.usedrange.Rows.Count
xlSheet.Range("A1").Activate
Do Until xlApp.activecell = ""
For iCtr = 1 To iListCount
If xlApp.activecell.Row <> xlSheet.cells(iCtr, 1).Row Then
If xlApp.activecell.Value = xlSheet.cells(iCtr, 1).Value Then
' a duplicate name was found
If xlApp.activecell.offset(0, 1).Value = xlSheet.cells(iCtr, 2).Value Then
If xlApp.activecell.offset(0, 2).Value = xlSheet.cells(iCtr, 3).Value Then
' a duplicate student was found
xlSheet.cells(iCtr, 1).Delete shift:=-4162
iCtr = iCtr + 1
End If
End If
End If
End If
Next iCtr
xlApp.activecell.offset(1, 0).Select
Loop
End Sub
In the above code I am refering to the cells by value rather than by text, this is because I'm not sure how to deal with Unicode in vb. In C its a nightmare sometimes trying to distinguish between the various encodings.

DKenny
Mar 9th, 2006, 08:57 AM
In the line where you are comparing the strings, you should convert both to either Upper or Lower case, that will make the comparison case independant.

If UCase(String1) = UCase(String2)....

waldermort
Mar 9th, 2006, 09:38 AM
Ahh thanks again. I remember you posted the same in your last code snippet for my benefit, I wasn't sure what Ucase did, but it worked so i never questioned it.

Your help is very much appreciated :D

DKenny
Mar 9th, 2006, 10:29 AM
Don't forget to mark this thread as complete, if your issue has been resolved. ;)