mercredi 25 mars 2020

I want to look if the cell value begins with the letters "PP*"

In excel I used this code in columnR:

=IF(COUNTIF(RC[-14],"*PP*")>0,"N",VLOOKUP(RC[-7],Mapping!R2C1:R22C19,2,FALSE)"

Now I wanted to turn it into VBA code.

In column D(RC-14) it looks if the word contains PP if so gives a N. When the word doesn't contain the letter PP then the Vlookup is used.

This is the code below: it does not spot when the value in D starts with PP* and always go to the else loop. Can somebody help me please :)

Dim RowCounter As Integer
RowCounter = 1

While wsBPT.Range("A1").Offset(RowCounter, 0).Value <> ""   'only fill in when there is data
If wsBPT.Range("D1").Offset(RowCounter, 0).Value = "*PP*" Then   'when isin starts with PP
        wsBPT.Range("A1").Offset(RowCounter, 17).FormulaR1C1 = "=VLOOKUP("PP",'Mapping'!R2C1:R10C2,2,FALSE)"
        RowCounter = RowCounter + 1
    Else: wsBPT.Range("A1").Offset(RowCounter, 17).FormulaR1C1 = "=VLOOKUP(RC[-7],'Mapping'!R2C1:R10C2,2,FALSE)" 'isin doesnot contain PP
        RowCounter = RowCounter + 1
End If
        Wend

Aucun commentaire:

Enregistrer un commentaire