使用vba将特定值从文本文件复制到另一个Excel工作表

时间:2016-04-20 18:30:04

标签: excel vba excel-vba

This is the result what i want This is the source file link

我正在尝试从文本中提取某些数据

file(C:\Users\mondals\Desktop\Source.txt)到Excel电子表格中。我正在使用MS Office 2010。我将文件保存为TEXT格式的文件,现在我需要从文本文件中提取信息。这是我需要从文本文件中提取的信息列表: 以

开头的行
103 0 TestTime
203 0 TestTime
303 0 TestTime
403 0 TestTime
503 0 TestTime
603 0 TestTime
703 0 TestTime
803 0 TestTime

示例:

103 0 TestTime -1 0.0000 mSec 60.3948 mSec 4000.0000 mSec 0.0000 m 0

从这一行我想复制60.3948等等。

注意:请查看附件doc Result.xlsx

而且......

从以下行我想复制值

104 0 TimeStdDev
204 0 TimeStdDev
304 0 TimeStdDev
404 0 TimeStdDev
504 0 TimeStdDev
604 0 TimeStdDev
704 0 TimeStdDev
804 0 TimeStdDev

示例:104 0 TimeStdDev -1 0.0000 mSec 2.6139 mSec 10000.0000 mSec 0.0000 m 0 从这一行我必须复制2.6139。

附加样本txt文件和所需输出excel文件

txt file = Source.txt这个thetxt文件我有

Xlsx file = Result.xlsx这是我想要的excel

注意:请浏览顶部的链接

真的很感谢你的帮助!!!!

在这里" s我尝试了什么

Sub Demo()
    v = ThisWorkbook.Path & "C:\Users\subhajit\Desktop\Autmation\data.txt"
    If Dir(v) = "" Then Beep: Exit Sub
    F% = FreeFile
    Open v For Input As #F
    v = Filter(Filter(Split(Input(LOF(F), #F), vbNewLine), vbTab), "TestTime Avg")
    Close #F
    If UBound(v) < 0 Then Beep: Exit Sub
    ReDim VA#(0 To UBound(v), 0)
    For F = 0 To UBound(v):  VA(F, 0) = Val(Split(v(F), vbTab)(1)):  Next
    With Worksheets(1).Cells(1)
       .CurrentRegion.Clear
        Resize(F).Value = VA
    End With
    v = ThisWorkbook.Path & "C:\Users\subhajit\Desktop\Autmation\data.txt"
    If Dir(v) = "" Then Beep: Exit Sub
    F% = FreeFile
    Open v For Input As #F
    v = Filter(Filter(Split(Input(LOF(F), #F), vbNewLine), vbTab), "TestTime StdDev")
    Close #F
    If UBound(v) < 0 Then Beep: Exit Sub
    ReDim VA#(0 To UBound(v), 0)
    For F = 0 To UBound(v):  VA(F, 0) = Val(Split(v(F), vbTab)(1)):  Next
    With Worksheets(1).Cells(2)
       'CurrentRegion.Clear = False
       .Resize(F).Value = VA
    End With
End Sub

0 个答案:

没有答案