VBA 1500×34×2000去掉×分隔成三个单元格数值
Sub SeparateNumbers() Dim str As String Dim num1 As Long, num2 As Long, num3 As Long
str = "1500×34×2000"
num1 = Val(Left(str, InStr(str, "×") - 1))
num2 = Val(Mid(str, InStr(str, "×") + 1, InStrRev(str, "×") - InStr(str, "×") - 1))
num3 = Val(Right(str, Len(str) - InStrRev(str, "×")))
Range("A1:C1").Value = Array(num1, num2, num3)
End Sub
Explanation:
- Declare variables to store the three numbers.
- Assign the input string to a variable.
- Use the Left, Mid, and Right functions to extract each number from the string.
- Convert each extracted string to a number using the Val function.
- Assign the three numbers to the cells A1 to C1 in the active worksheet
原文地址: https://www.cveoy.top/t/topic/fkRI 著作权归作者所有。请勿转载和采集!