我正在尝试统计文本文件中特定列的数据,我认为最好的方法是将文本文件的所有内容复制到Excel工作表中,然后从那里进行统计(否则我需要直接从Excel文件中尝试读取该行)。以下是我目前的代码:
Dim filePath As String
Dim currentValue As String
Dim iRow As Long
Dim iCol As Long
Dim badAddress As Long
Dim coverageNoListing As Long
Dim activeListing As Long
Dim noCoverageNoListing As Long
Dim inactiveListing As Long
Dim fso As Object
Dim f As Object
'' filePath would include entire file name (picked from a browser button)
filePath = ActiveSheet.Range("B2").Text
'' Makes sure there isn't a sheet named "Temp_Text_File"
For Each testSheet In ActiveWorkbook.Worksheets
If testSheet.Name Like "Temp_Text_File" Then flag = True: Exit For
Next
'' If there is a sheet named "Temp_Text_File" it will be deleted
If flag = True Then
Application.DisplayAlerts = False
ActiveWorkbook.Sheets("Temp_Text_File").Delete
Application.DisplayAlerts = True
End If
'' Recreate sheet
Sheets.Add.Name = "Temp_Text_File"
'' Here I would want to copy everything (similar to manually doing "Ctrl+A" then "Ctrl+C") from the text file
'' Then paste into worksheet (similar to manually doing "Ctrl+V") within this created worksheet range("A1")
'' Delete at the end (user has no need for it)
Application.DisplayAlerts = False
ActiveWorkbook.Sheets("Temp_Text_File").Delete
Application.DisplayAlerts = True
谢谢,
杰西·斯莫瑟蒙