Consulting

Results 1 to 7 of 7

Thread: VBA Like statement

  1. #1

    Unhappy VBA Like statement

    Is my syntax wrong here?

    Trim(Range(sRange).Text) Like Not "Page" Then

  2. #2
    sorry, heres my whole code. what am i missing?



    If Trim(Range(sLeftRange).Text) <> UCase(Trim(Range(sLeftRange).Text)) And 
    
    Trim(Range(sRange).Text) Like Not "Page" Then
    Range(sLeftRange).Interior.ColorIndex = iColour End If

  3. #3
    changed to this, but still same problem....



    If Trim(Range(sLeftRange).Text) <> UCase(Trim(Range(sLeftRange).Text)) And Not Trim(Range(sLeftRange).Text) Like "Page" Then
                                    Range(sLeftRange).Interior.ColorIndex = iColour
                                End If

  4. #4

  5. #5
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Hi crmpicco,

    Yes, your syntax is wrong, try this

    Sub LikeItOrNot()
    Dim sRange
    sRange = "A1"
    If Not Trim(Range(sRange).Text) Like "Page" Then
    MsgBox "Not Page"
    Else
    MsgBox "Page"
    End If
    End Sub
    Note that while 'like' can be used as shown above for an exact match, the 'like' atatement is usually used with a wild-card character to find similar words E.G. "*Page" will give "Front Page", "Last Page",...etc. OR, "Page*" will give "Page one", Page two", etc.

    HTH,
    John
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  6. #6
    nice 1:


    If Trim(Range(sLeftRange).Text) <> UCase(Trim(Range(sLeftRange).Text)) And Not Trim(Range(sLeftRange).Text) Like "*Page*" Then
                                    Range(sLeftRange).Interior.ColorIndex = iColour
                                End If

  7. #7
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Not a prob, glad to be able to help
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

Posting Permissions

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