简体   繁体   中英

excel VBA macro to parse multi-line tabbed textbox

I'm fairly new making macros for excel and I think I'm being a bit too ambitious in my latest project. I basically want to parse the output of a piece of lab equipment to help me file cells in a file that I will use to process my experimental data.

I wanted to paste the raw output from the device in a text box, and then have a macro split the data across multiple cells. In the raw data, text is separated horizontally by tabs and vertically by line breaks.

Eg

data1 [tab] data2 [tab] data3 [Line break] data4 [tab] data5 [tab] data6 [LB]

and so on, which would then be parsed into 3 cells horizontally across 2 cells vertically.

Any ideas how to do this easily?

cheers Yossi.

You need to split the value of the textbox twice, first create rows, and then further split that into cells.

Dim rows As Variant
Dim columns As Variant
Dim i As Integer
Dim j As Integer

i = 1
rows = Split(TextBox1.Value, vbNewLine)

For Each r In rows

j = 1
columns = Split(r, vbTab)

For Each c In columns

Sheets("Sheet1").Cells(i, j).Value = c

j = j + 1

Next c
i = i + 1
Next r

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM