简体   繁体   English

Excel VBA宏来解析多行选项卡式文本框

[英]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. 我是制作Excel宏的新手,我认为我在最新的项目中有点过于野心勃勃。 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] data1 [tab] data2 [tab] data3 [换行符] data4 [tab] data5 [tab] data6 [LB]

and so on, which would then be parsed into 3 cells horizontally across 2 cells vertically. 依此类推,然后将其解析为水平3个单元格和垂直2个单元格。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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