简体   繁体   中英

extract string from cell

I have a situation like this in excel 2007:

.15X.04-1.25X.625-SD+str

.15X.04-1.25X1.25-SD

.15X.04-1.5X1.25-SD

.15X.04-1.75X1.75-SC

.15X.04-1X.625-SD+str

.15X.04-2.25X2.25-SC

.15X.04-2.5X2.5-SC

.15X.04-2.75X2.75-SC

.15X.04-2X1.75-SC

.15X.04-3X3-SC

.15X.06-1.25X.625-SD+str

. . . .

I need to extract the number between "-" and "X", OR the whole part ,like this: -1X; -1.25X; -1.5X; -1.75X and so on .

how can i do it?

如果您要从中获取数据的单元格位于单元格A1 ,则此公式可以做到:

=MID(A1,FIND("-",A1),FIND("X",A1,FIND("-",A1))-FIND("-",A1)+1)

This should work:

Private Function GetValue(ByVal cellLocation As String) As String

    Dim txt As String
    txt = Application.Range(cellLocation).text

    Dim split As String
    split = split(txt, "-")(0)

    Dim result As String
    result = split(partOne, "X")(0)

    GetValue = result

End Function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM