将单元格串拆分为单个单元格 [英] Split cell string into individual cells

查看:40
本文介绍了将单元格串拆分为单个单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法将单个单元格的值拆分为两个不同的字符串并将这两个字符串放在不同的单元格中.

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 作为字符串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"

这篇关于将单元格串拆分为单个单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆