如何在Excel VBA中解析完整字符串并拆分为多个字符串? [英] How to Parsing Full String and split into several String in Excel VBA?

查看:209
本文介绍了如何在Excel VBA中解析完整字符串并拆分为多个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要 Excel VBA 方面的帮助.我有一种情况,我需要从一个字符串中拆分成几个数据.现在有特定的分隔符,条件只是一个关键字.

I need help in Excel VBA. I have situation that i need to split into several data from a String. There is now specific delimiter, the condition is only a Keyword.

我得到的完整字符串数据的例子是这样的:

The example of the Full String Data i got is like this:

/*ORDER FORM*/
Name: Randy
Full Address: Unknown Street 123 ABC
Phone:0246854612
Order: 1x G Action Figure
1x Y Action Figure
2x Z Action Figure

/*Fill Bank and Amount of Transfer*/
Bank: ABC
Total: 2000

/*If you Reseller, Fill Data below*/
Sender:
SenderPhone:

/*Thank you for your Order*/

而且,从该数据中,我需要将多个数据发送到多个单元格或变量中.例如,如果我想得到这个:

And, From That data i need to send several Data into Several Cell or Variables. For examples, if i want to get this:

var Name = "Randy"

var address = "Unknown Street 123 ABC"

var phone = "0246854612" {Text format}

var Bank = "ABC"

var amount = 2000

var item1 = "G Action Figure"

var qty1 = 1 {from 1x G Action Figure}

var item2 = "Y Action Figure"

var qty2 = 1

var item3 = "Z Action Figure"

var qty3 = 2

我怎样才能做到这一点.

How can i Achieve this.

非常感谢

推荐答案

数据是否总是以相同的顺序出现并且总是相同的行数?您可以使用回车符拆分整个字符串.

Does the data always appear in the same order and are there always the same number of rows? You could split the whole string using a carriage return.

MySplit = Split(MyString,VbCrLf)

然后将数组的每个部分分配给一个变量.

And then assigning each part of the array to a variable.

Name = MySplit(0)
Address = MySplit(1)
Phone = MySplit(2)
'...etc...

这篇关于如何在Excel VBA中解析完整字符串并拆分为多个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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