How to Parsing Full String and split into several String in Excel VBA?

我只是一个虾纸丫 提交于 2020-01-25 19:21:07

问题


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.

thank you very much


回答1:


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...


来源:https://stackoverflow.com/questions/36787492/how-to-parsing-full-string-and-split-into-several-string-in-excel-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!