我们说我有一列价值观,如:
A
3' x 5'
4' x 6'
5' x 8'
6' x 9'
10' x 14'
2' 3 x 8'
如何将这些值拆分为整数,以便对它们进行操作?
对于前几个值,我显然想要乘以3 x 5
,4 x 6
等,但对于上面显示的最后一个值,它会变得棘手。在这种情况下,它需要2.25 x 8
(。25 == 3/12英寸)。这可能吗?
答案 0 :(得分:3)
首先确保使用TRIM删除开头和结尾的空格,然后使用:
=(LEFT(A1;FIND("'";A1)-1)+("0" & MID(A1;FIND("'";A1)+2;FIND("x";A1)-FIND("'";A1)-2))/12)*MID(A1;FIND("x";A1)+1;LEN(A1)-FIND("x";A1)-1)
根据您的区域设置,您可能需要更换";" by","
答案 1 :(得分:3)
尝试一下:
Public Function area(s As String) As Variant
Dim ary, ti As String, leng(0 To 1) As Double, i As Long
Dim bry
ti = Chr(39)
ary = Split(Replace(s, " ", ""), "x")
For i = 0 To 1
If Right(ary(i), 1) = ti Then
leng(i) = CDbl(Mid(ary(i), 1, Len(ary(i)) - 1))
Else
bry = Split(ary(i), ti)
leng(i) = CDbl(bry(0)) + CDbl(bry(1)) / 12
End If
Next i
area = leng(0) * leng(1)
End Function