rprt.net
当前位置:首页 >> vBAtxt循环写入ExCEl >>

vBAtxt循环写入ExCEl

直接打开,粘贴数据即可,代码如下:Sub xx() Dim wb As Workbook Set wb = Workbooks.Open(Filename:=ThisWorkbook.Path & "\1.txt", Format:=6, delimiter:=" ") '打开1.txt Sheet1.[a1:b4] = WorksheetFunction.Transpose(wb.Sheets(1).[a1:d2].Value) '粘贴数据 wb.Close False '关闭1.txt End Sub

复制 粘贴 就好了.

公式部分有个迭代设置但是不算循环写入的楼主要使用循环写入的话建议使用vba实现循环可以考虑使用for,do while,goto语句之类的

首先是这个多个for循环,是用什么语言写的?如果是vba的话,根据具体循环结果就直接写入excel即可或者写入txt文件建议楼主再明确下需求吧

在多个txt文件的文件夹中新建一个EXCEL,在其VBA中输入ReadTextFiles(),然后运行:Sub ReadTextFiles()Dim n As Long, a(), ff As Integer, txt As String, myDir As String, xDim myF As String, i As LongmyDir = ThisWorkbook.Path &

假设你的文件名为:textfile.txt,并在"我的文档"里面Sub ImportRange() Dim ImpRng As Range Dim Filename As String Dim r As Long, c As Integer Dim txt As String, Char As String * 1 Dim Data Dim i As Integer Set ImpRng = ActiveCell On

你好,vba不能读取txt的一列,只能先读取到行,然再到列,我给你举个例子吧 假设d盘文件夹123中,有一个456的txt文件,456.txt的第10行为:a-b-c ,现在将b读取到sheet1的a1单元格.下面是代码 sub ff() dim a,k%,i% open "d:\123\456.txt"

例如从同一目录下导入名为 test的文本文件:Dim fn As Integer, i As IntegerDim MyStr As Stringfn = FreeFile Open ThisWorkbook.Path & "\test.txt" For Input As fn For i = 1 To 4 Line Input #fn, MyStr Next i = 1 While Not EOF(fn) Line Input #fn, MyStr Sheet1.Cells(i, 1) = MyStr i = i + 1 Wend Close fnEnd Sub

直接将txt 文件的扩展名改成xls,然后用语句打开xls文件,用cells(1,1).value语取每一行的数据,不会丢失空格

在循环内插入一行DoEvents试试

网站首页 | 网站地图
All rights reserved Powered by www.rprt.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com