分割字符串和打印到不同的单元格,Excel VBA [英] Splitting Strings And Printing Into Different Cells, Excel VBA

查看:127
本文介绍了分割字符串和打印到不同的单元格,Excel VBA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是VBA的新手,已经开始解决这个问题了。我有一个三个字符的字符串,我想分割并将值放在一个数组中的excel。所以例如,

  Sub Splitdata()

Dim x As Variant
Dim txt作为字符串

txt =今天是晴天
x =拆分(txt)

范围(C1:C3)值= x

End Sub

但是,这只能从单元格C1-c3中的字符串中返回第一个字符即今天。我想象一个循环是必需的,但我不知道如何制作一个。还有一种解决这个问题的一般方法?

解决方案

是的,您可以通过将分割行更改为这一个:

  x =拆分(txt,)

编辑:并将更改结果的行更改为:

  Range(C1:C3)。Value = Application.Transpose(x)


I'm new to VBA and have been cracking my head to solve this problem. I have a string of three characters which I want to split and place the values into an array in excel. So for instance,

Sub Splitdata()

Dim x As Variant
Dim txt As String

txt = "Today is sunny"
x = Split(txt)

Range("C1:C3").Value = x

End Sub

However this only returns the first character from the string in cells C1-c3 i.e. "Today". I imagine a loop is required, however I'm not sure how to make one yet. Is there also a general way of solving this problem?

解决方案

Yes, you could simply solve your problem by changing your splitting line into this one:

x = Split(txt, " ")

Edit: and change the line which passes result to sheet into this:

Range("C1:C3").Value = Application.Transpose(x)

这篇关于分割字符串和打印到不同的单元格,Excel VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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