Results 1 to 4 of 4

Thread: [RESOLVED] Cell comparisons

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    8

    Resolved [RESOLVED] Cell comparisons

    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?
    VB Code:
    1. Sub RemoveDuplicates()
    2.     Dim iListCount As Integer
    3.     Dim iCtr As Integer
    4.  
    5.     iListCount = xlSheet.usedrange.Rows.Count
    6.     xlSheet.Range("A1").Activate
    7.     Do Until xlApp.activecell = ""
    8.        For iCtr = 1 To iListCount
    9.           If xlApp.activecell.Row <> xlSheet.cells(iCtr, 1).Row Then
    10.              If xlApp.activecell.Value = xlSheet.cells(iCtr, 1).Value Then
    11.                 ' a duplicate name was found
    12.                 If xlApp.activecell.offset(0, 1).Value = xlSheet.cells(iCtr, 2).Value Then
    13.                     If xlApp.activecell.offset(0, 2).Value = xlSheet.cells(iCtr, 3).Value Then
    14.                         ' a duplicate student was found
    15.                         xlSheet.cells(iCtr, 1).Delete shift:=-4162
    16.                         iCtr = iCtr + 1
    17.                     End If
    18.                 End If
    19.              End If
    20.           End If
    21.        Next iCtr
    22.        xlApp.activecell.offset(1, 0).Select
    23.     Loop
    24. 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.

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Cell comparisons

    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.

    VB Code:
    1. If UCase(String1) = UCase(String2)....
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    8

    Re: Cell comparisons

    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

  4. #4
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: [RESOLVED] Cell comparisons

    Don't forget to mark this thread as complete, if your issue has been resolved.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width