+ Reply to Thread
Results 1 to 5 of 5

Like Operator Not Working for Character List

Hybrid View

  1. #1
    Registered User
    Join Date
    10-03-2012
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    44

    Like Operator Not Working for Character List

    Hi All,

    When I run this code it does the exact opposite of what I want it do (if not contained in that character list then delete). So basically if it not in the character list then delete, but it if is in the character list it deletes....

    Sub GetData()
    
    Dim A As Long
    Dim lngCounterStop As Long
    
    lngCounterStop = Range("B2").End(xlDown).Offset(1)
    
    A = 1
    Do
    A = A + 1
    If Not Cells(A, 2).Value Like "[F*,H*,I*,K*,O*,Q*,U*,V*,X*,Y*,Z*,0*,1*,2*,3*,4*,5*,6*,7*,8*,9*]" Then
        Rows(A).EntireRow.Delete
    End If
    Loop Until Cells(A, 2) = lngCounterStop
    End Sub

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Like Operator Not Working for Character List

    Are you trying to check the first character to see if it is/isn't in the list?
    If Not Left(Cells(A, 2).Value,1) Like "[F,H,I,K,O,Q,U,V,X,Y,Z,0,1,2,3,4,5,6,7,8,9]" Then
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    10-03-2012
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Like Operator Not Working for Character List

    Yes, I am trying to check the first character and then any data after it. Basically a begins with.

    Thanks for your respone, but why couldn't I use * and need to use the left function? I used LIKE before such as "ABC*" and it worked ok.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Like Operator Not Working for Character List

    What's between the [] is a character list, ie a list of single characters.

    If you don't want to use Left you could try Like "[characterlist]*".

  5. #5
    Registered User
    Join Date
    10-03-2012
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Like Operator Not Working for Character List

    Thanks for the information. That makes sense to me now. I didn't know [] treated the list as a single character.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 08-23-2013, 05:45 PM
  2. Find and Replace not working on the pipe ( | ) character
    By Excel_vba in forum Excel General
    Replies: 1
    Last Post: 06-28-2013, 04:20 PM
  3. Replace not working when character length exceeded
    By tryer in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-31-2013, 02:48 PM
  4. 603 character hyperlink not working
    By Mycotopian in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-20-2011, 05:56 AM
  5. Help w/ selecting operator from list...
    By Rackman in forum Excel General
    Replies: 2
    Last Post: 04-08-2009, 07:51 PM

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