dimanche 28 février 2021

VBA IF cell VALUE LENGTH criteria

I have a code:

IF s LIKE "UZL.*" AND s LIKE "*.ENG" THEN

It evaluates if cell value starts with "UZL." and ends with ".ENG" but I would like to change those second criteria ".ENG" to be cell length =16 symbols. So it's like

If s Like "UZL.*" And cell value length =16 Then

Can someone please say what would be the code for that?

Full code:

Dim vDB As Variant
Dim rngDB As Range
Dim s As String, sReplace As String
Dim i As Long
Dim Ws As Worksheet

Set Ws = Sheets("BOM")

On Error Resume Next
Worksheets("BOM").ShowAllData
 
With Ws
    Set rngDB = .Range("E2", .Range("E" & Rows.Count).End(xlUp))
End With
vDB = rngDB
For i = 1 To UBound(vDB, 1)
    s = vDB(i, 1)
    If s Like "UZL.*" And s Like "*.ENG" Then
        sReplace = Me.LanguageBox.Value
        s = Replace(s, "ENG", sReplace)
        vDB(i, 1) = s
    End If
Next i
rngDB = vDB

Aucun commentaire:

Enregistrer un commentaire