Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    May 2015
    Posts
    104
    Thanks
    15
    Thanked 0 Times in 0 Posts

    I need help with one If statement...

    Hi Guys,

    Can anyone tell me why the highlighted line never returns yes when both sides of the equation are 1?

    Code:
    '**************************************
    'Seach for match on Stock...
    '**************************************
        With shtSK                                                          'on Stock
        MsgBox "on Stock"
            For I = 3 To LRow Step 1                                        'from 3 to last item row
            MsgBox "inside For"
                If .Cells(I, "I") = Target Then                             'if name match
                    MsgBox "Name Match found"
    
                    MsgBox "LID:"
                    MsgBox .Cells(I, "M")                                   'result is 1
    
    
                    MsgBox "Active Sheet Name:"                      
                    MsgBox ActiveSheet.Name                                 'result is 1
    
                    If .Cells(I, "M") = ActiveSheet.Name Then               'if LID match
                        MsgBox "LID Match"
                        r = r + 1                                           'increase row number
                        MsgBox "Match found, going to next item..."
                        GoTo Line1                                          'continue with the next item
                    End If
                End If
            Next I
        End With
    Last edited by Ferenc Nagy; 2015-07-18 at 10:15.

  2. #2
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,164
    Thanks
    47
    Thanked 976 Times in 906 Posts
    Maybe this will be better?
    If .Cells(I, "M").Value = ActiveSheet.Name Then

    Or they have white space.
    If trim(.Cells(I, "M").Value) = trim(ActiveSheet.Name) Then

    cheers, Paul

  3. #3
    2 Star Lounger
    Join Date
    May 2015
    Posts
    104
    Thanks
    15
    Thanked 0 Times in 0 Posts
    Thanks Paul

    Quote Originally Posted by Paul T View Post
    Maybe this will be better?
    If .Cells(I, "M").Value = ActiveSheet.Name Then

    Or they have white space.
    If trim(.Cells(I, "M").Value) = trim(ActiveSheet.Name) Then

    cheers, Paul
    Trim worked, but could you tell me why was it necessary? I would like to understand it...

    Ferenc

  4. #4
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,629
    Thanks
    114
    Thanked 644 Times in 588 Posts
    Or could it be that one returns a number
    .Cells(I, "M")

    and the other returns a string?
    ActiveSheet.Name

    HTH,
    Maud

  5. #5
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,629
    Thanks
    114
    Thanked 644 Times in 588 Posts
    See if this change resolves the problem

    If Str(.Cells(I, "M")) = ActiveSheet.Name Then

  6. #6
    2 Star Lounger
    Join Date
    May 2015
    Posts
    104
    Thanks
    15
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Maudibe View Post
    See if this change resolves the problem

    If Str(.Cells(I, "M")) = ActiveSheet.Name Then
    This did not make it work, but trim seems to work fine...
    I wonder if I will see issues when the sheet name has other characters as well, not just numbers...

Posting Permissions

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