mardi 21 juin 2016

How to match String with Number in VBA

Hope someone can help me with this.

Objective:I am trying to match 2 cells of information where,

Cell 1 data: Chicken1234 Cell 2 data: 1234

Cell 2 will determine how many characters of cell 1 from the right to be used for the matching criteria. Therefore in excel context it should be =if(cell2=(right(cell1,len(cell2)),"True","False")

Please tell me what am I doing wrong and how I can better this.

sample data:

Meat |Chicken1234 |Answer True or False

MeatNo |1234 |Answer True or False

Sub matchingtest()

Dim MTAC As Variant, BankAC As Variant


[A1].Select

MeatNo = ActiveCell.Offset(1, 1)
No = ActiveCell.Offset(0, 1)

Do While Not IsEmpty(ActiveCell.Offset(1, 0))

    If Not IsEmpty(ActiveCell) And _
        No = MeatNo Then _

            ActiveCell.Offset(0, 3).FormulaR1C1 = ("True")
            ActiveCell.Offset(1, 0).Select

        Else

           ActiveCell.Offset(0, 10).FormulaR1C1 = ("False")
           ActiveCell.Offset(1, 0).Select

    End If

Loop



End Sub

Aucun commentaire:

Enregistrer un commentaire