将单元格字符串拆分成单个单元格
我无法将单个单元格的值分割成两个不同的字符串,并将这两个字符串放在不同的单元格中。
I am unable to split a single cell's value into two different strings and put both of those strings in different cells.
例如,我想在单元格中进行 10ft x 20ft
的测量,并采取 10ft
并将其放在另一个单元格中,并将 20ft
放在一个完全不同的单元格中。
For instance I want to take a measurement 10ft x 20ft
value in a cell and take the 10ft
and put it in another cell, and take the 20ft
and put it in a completely different cell.
我想使用分隔符 x
或某事,但我只是不知道如何采取这些分离,并在分裂后与他们做某事。
I'd like to use a delimiter x
or something, but I just don't know how to take those separations and do something with them after the split.
任何提示将不胜感激。我还是相当新的VBA宏。
Any tips would be much appreciated. I'm still pretty new to VBA macros.
谢谢
最好的解决方案是使用SPLIT
The best solution is using SPLIT
Dim strX As String
Dim sx() As String
Dim i as Integer
strX = "10FT x 20FT"
sx = Split(strX, "x")
或者你可以使用instr函数
Or maybe you can use instr function
Dim sVar1 as string
Dim sVar2 as string
I = InStr(1, strX, "x")
你知道哪里可以拆分两个变量
Now you know where can split int two variables
sVar1 = mid(strX, 1, I)
sVar2 = mid(strx,i+1)
该功能的问题是如果您在链中有多个键你要与其分开你的函数会返回一个更大的数组。
例如:
Dim var as string
var =x 20XP 10XP
The problem with the function is that if you have several keys in the chain with which you want to separate your function will return an array larger. For example: Dim var as string var = "x 20XP 10XP"
返回
array (0) = "10"
array (1) = "p"
array (2) = "20"
array (3) = "p"