+ Reply to Thread
Results 1 to 8 of 8

non-case sensitive 'string' search?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-29-2011
    Location
    Scotland
    MS-Off Ver
    Excel 2003
    Posts
    122

    non-case sensitive 'string' search?

    im using the code below to find the text 'Filming' in a column i specify then delete that row, however, it is case sensitive, i.e. it will not delete the row if comes accross 'filming'.
    i assumed that using the wildcards * that it would know what to do, but it doesnt.

    any ideas how to fix this?

     
       lastrow = Cells(Rows.Count, astColumn).End(xlUp).Row
        For Ptr = 1 To lastrow
          If Cells(Ptr, astColumn) Like "*Filming*" Then   ' <- Filming is case sensitive
                If RangeToDelete Is Nothing Then
                    Set RangeToDelete = Cells(Ptr, astColumn)
                Else
                    Set RangeToDelete = Union(RangeToDelete, Cells(Ptr, astColumn))
                End If
            End If
        Next Ptr
        If Not RangeToDelete Is Nothing Then
            RangeToDelete.EntireRow.Delete
        End If

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: non-case sensitive 'string' search?

     If lCase(Cells(Ptr, astColumn)) Like "*filming*" Then
    Gary's Student

  3. #3
    Forum Contributor
    Join Date
    06-29-2011
    Location
    Scotland
    MS-Off Ver
    Excel 2003
    Posts
    122

    Re: non-case sensitive 'string' search?

    that doesnt work. thats the same as
    If Cells(Ptr, astColumn) Like "*filming*" Then
    it wont see 'Filming'. most entries are 'Filming', a few are 'filming'.

  4. #4
    Forum Contributor
    Join Date
    06-29-2011
    Location
    Scotland
    MS-Off Ver
    Excel 2003
    Posts
    122

    Re: non-case sensitive 'string' search?

    Quote Originally Posted by Jakobshavn View Post
     If lCase(Cells(Ptr, astColumn)) Like "*filming*" Then
    that doesnt work. thats the same as
    If Cells(Ptr, astColumn) Like "*filming*" Then
    it wont see 'Filming'. most entries are 'Filming', a few are 'filming'.

  5. #5
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: non-case sensitive 'string' search?

    Try this instead of like

    If InStr(1, Cells(ptr, astColumn), "Filming", vbTextCompare) > 0 Then
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  6. #6
    Forum Contributor
    Join Date
    06-29-2011
    Location
    Scotland
    MS-Off Ver
    Excel 2003
    Posts
    122

    Re: non-case sensitive 'string' search?

    Quote Originally Posted by mike7952 View Post
    Try this instead of like

    If InStr(1, Cells(ptr, astColumn), "Filming", vbTextCompare) > 0 Then
    That works, cheers Mike!!

    Can you explain how it works?

    i know the syntax for the INSTR function is:
    InStr( [start], string, substring, [compare] )

    is it the case that vbTextCompare 'is-not' case sensitive?

    how does the > 0 part work?
    Last edited by intothewild; 11-25-2012 at 02:36 PM.

  7. #7
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: non-case sensitive 'string' search?

    @intothewind

    Heres a link explaning the Instr function http://www.aivosto.com/vbtips/instr.html
    Jakes solution will work. Did you try it? Here's a couple of examples.

    Sub abc()
     s = "FiLMiNg"
     
     ' Lcase will turn FiLMiNg into filming therefor will be like filming
     If LCase(s) Like "*filming*" Then MsgBox "Like filming"
     
     ' Ucase will turn FiLMiNg into FILMING therefor will be like FILMING
     If UCase(s) Like "*FILMING*" Then MsgBox "Like FILMING"
    End Sub

  8. #8
    Forum Contributor
    Join Date
    06-29-2011
    Location
    Scotland
    MS-Off Ver
    Excel 2003
    Posts
    122

    Re: non-case sensitive 'string' search?

    Thanks Mike the link is really good. I did try Jakes but it didnt work for me, i'll try again

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1