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:

  1. Declare variables to store the three numbers.
  2. Assign the input string to a variable.
  3. Use the Left, Mid, and Right functions to extract each number from the string.
  4. Convert each extracted string to a number using the Val function.
  5. Assign the three numbers to the cells A1 to C1 in the active worksheet
VBA 1500×34×2000去掉×分隔成三个单元格数值

原文地址: https://www.cveoy.top/t/topic/fkRI 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录