转换和计算 beetwean 2 值

Convert and count beetwean 2 values

我需要帮助 Excel 在 2 个值之间进行转换,例如:

我有数值“27-30”我想转换为“27,28,29,30”

和值字符"S-XL"我想转换成"S, M, L, XL"

数字 28,29 and so on 可以轻松循环,但对于像 S, M and L 这样的尺寸,您需要查找 table。

Column A 包含您的尺寸和 Column E,查找 non-numeric 尺寸,

代码在这里,结果在Column B

Sub sizes()
Dim i As Long, j As Long, str As String, rownum As Long
For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row
    If IsNumeric(Left(Cells(i, 1), InStr(Cells(i, 1), "-") - 1)) Then
        str = Left(Cells(i, 1), InStr(Cells(i, 1), "-") - 1)
        For j = Left(Cells(i, 1), InStr(Cells(i, 1), "-") - 1) + 1 To _
                Mid(Cells(i, 1), InStr(Cells(i, 1), "-") + 1, 999)
            str = str & " , " & j
        Next j
        Cells(i, 2) = str
    Else
        rownum = Application.WorksheetFunction.Match(Left(Cells(i, 1), InStr(Cells(i, 1), "-") - 1), Range("E:E"), 0)
        str = Cells(rownum, 5)
        rownum = rownum + 1
        Do Until (Cells(rownum, 5) = Mid(Cells(i, 1), InStr(Cells(i, 1), "-") + 1, 999))
            str = str & " , " & Cells(rownum, 5)
            rownum = rownum + 1
        Loop
        str = str & " , " & Cells(rownum, 5)
        Cells(i, 2) = str
    End If
Next i
End Sub