Share via

How to compare cell with array?

Anonymous
2011-01-05T07:01:58+00:00

hi

  i am trying to compare cell of a range with array value, both the value ar same but its not showing msg, code is :-

For Each cell In rng4

        For j = 1 To 180 Step 1

          If Len(cell) = 5 Then

            cell = "200" & cell  ' addig 200 in front of cell value

          End If

          If arr(j, 1) = cell Then  'here i am matching the values.

                wkb2.Activate

                Application.Range(str3 & j).Copy

                wkb1.Activate

                Application.Range(str7 & j).Select

                Selection.PasteSpecial Paste:=xlPasteValues

                ActiveCell.Offset(0, 1).Select

          End If

        Next j

 Next

Please help me on this.

Thanks, Nitin.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2011-01-05T13:48:32+00:00

    Am 05.01.2011 08:01, schrieb Er. Nitin Pandey:

    i am trying to compare cell of a range with array value, both the value ar same but its not showing msg, code is :-

    Most errors were made in comparisons:

    a.) One of the strings has a trailing space

    b.) The spelling of the strings is not the same

    Therefore, it is advisable to remove the spaces and use the comparison options:

    --- schnipp ---

    Option Compare Text

    Sub Test()

      If Trim$(" Andreas") = Trim$("andreas ") Then _

        MsgBox "Strings are equal"

    End Sub

    --- schnapp ---

    or

    --- schnipp ---

    Sub Test()

      If StrComp(Trim$(" Andreas"), Trim$("andreas "), vbTextCompare) = 0 Then _

        MsgBox "Strings are equal"

    End Sub

    --- schnapp ---

    Andreas.

    Was this answer helpful?

    0 comments No comments