分割字符串和打印到不同的单元格,Excel VBA [英] Splitting Strings And Printing Into Different Cells, Excel VBA
问题描述
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屋!