如何使用VBA将制表符分隔的数据导入Excel [英] How to import tab delimited data into Excel using VBA

查看:438
本文介绍了如何使用VBA将制表符分隔的数据导入Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定我从Excel导入的制表符分隔的数据,如何将其插入电子表格中,以使其像粘贴时一样位于多个单元格中.

Given tab delimited data that I am importing from Excel, how do I insert it into the spreadsheet so that it ends up in multiple cells like it does when I paste it.

编辑:我将文本包含在变量中,所以我不想遍历文件系统.

I have the text in a variable, so I don't want to go through the file system.

推荐答案

这基本上是我最终想出的,它稍微复杂一些并使用了数组,但这就是要点.

This is basically what I finally came up with, it was a little more complex and used arrays, but that is the gist of it.

i = 1
For Each Row In VBA.Split(text, vbCrLf)
    j = 1
    For Each Col In VBA.Split(Row, vbTab)
        ActiveSheet.Cells(i, j).Value = Col
        j = j + 1
    Next Col
    i = i + 1
Next Row

这篇关于如何使用VBA将制表符分隔的数据导入Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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