Extract number from string in VBA

后端 未结 4 1515
攒了一身酷
攒了一身酷 2020-12-21 09:51

I have cells in vba that contain strings like this:

QUANTITY SUPPLY <= DAYS SUPPLY|30 IN 23 DAYS

I send these strings through two functions that just pick

4条回答
  •  渐次进展
    2020-12-21 10:17

    Have you considered using the "Split" function in VBA? If it is always pipe delimited, you could try:

    Public Function extractQLlMax(cellRow, cellColumn) As String
        Dim X as Variant
        qlm = Cells(cellRow, cellColumn).Value
        extractQLlMax = qlm
    
        If extractQLinfoBool = "Yes" And Not InStr(1, qlm, "IN") = 0 Then
            If InStr(1, qlm, "QUANTITY SUPPLY") > 0 Then
            x = Split(qlm,"|")
            extractQLlMax = X(ubound(x))
        ElseIf extractQLinfoBool = "Yes" And Not InStr(1, qlm, "FILL") = 0 Then
            perIndex = InStr(1, qlm, "PER")
            extractQLlMax = Mid(qlm, 1, perIndex - 2)
        End If
    End Function
    

提交回复
热议问题