各位VBA的高手,
我在撰寫一個資料處理的VBA,遇到一個問題,不知如何解決,請高手幫忙看一下代碼那里有問題?
資料是機器自動產出匯總一天的資料,但格式上不好處理這些資料,所以我把這些專案分成不同的列,運行一個VBA去整理這些資料,資料在附件中,資料從3:001 ~ 4:001:0為一組資料,一份檔案中重復幾百個相同的資料,要把它變成橫向的,這一組資料要變成一行,下面的一組資料要放在第二行,以此類推。相似的檔案有100多份,全部要匯總到一張表里處理
代碼要怎么修改才能讓每一組資料在一行,并且一份檔案中的所有資料都出來?
我這份代碼,運行完了,每份檔案只留下了最后一組資料。
3:001:排料圖的ID 8130布-抱枕A3件.cut
3:002:排料圖的長度 1.06
3:003:排料圖的寬度 1.25
3:004:部件數 9
3:005:剪裁時期 2019/11/01
3:006:剪裁開始時間 8:21:27
3:007:剪裁結束時間 8:23:24
3:008:剪裁時間 0:01:57
3:009:平均剪裁速度 10.83
3:010:剪裁距離 14.62
3:011:刀片上升轉換角度 140.00
3:012:刀具轉換的角度 15.00
3:013:剪裁速度(高速) 45
3:014:剪裁速度(低速) 43
3:027:剪裁時間22 0:01:53
4:001:0 5
3:001:排料圖的ID 8130布-抱枕B.cut
3:002:排料圖的長度 0.49
3:003:排料圖的寬度 1.01
3:004:部件數 3
3:005:剪裁時期 2019/11/01
3:006:剪裁開始時間 8:28:16
3:007:剪裁結束時間 8:29:03
3:008:剪裁時間 0:00:47
3:009:平均剪裁速度 9.87
3:010:剪裁距離 4.93
3:011:刀片上升轉換角度 140.00
3:012:刀具轉換的角度 15.00
3:013:剪裁速度(高速) 45
3:014:剪裁速度(低速) 43
3:027:剪裁時間22 0:00:44
4:001:0 5
3:001:排料圖的ID KF2033布-1.5右.cut
3:002:排料圖的長度 3.92
3:003:排料圖的寬度 1.40
3:004:部件數 20
3:005:剪裁時期 2019/11/01
3:006:剪裁開始時間 8:30:01
3:007:剪裁結束時間 8:36:37
3:008:剪裁時間 0:06:36
3:009:平均剪裁速度 9.29
3:010:剪裁距離 40.08
3:011:刀片上升轉換角度 140.00
3:012:刀具轉換的角度 15.00
3:013:剪裁速度(高速) 45
3:014:剪裁速度(低速) 43
3:027:剪裁時間22 0:06:19
4:001:0 5
下面是VBA的代碼:
Sub TEST()
Dim row As Long
row = 4
Range("A4:Q30000").Clear
Dim filePath As String
'filePath = "D:\Marker report"
Sheet1.Select
filePath = Sheet1.Range("F2").Value
Dim fs As New FileSystemObject
Dim f As File
Dim fo As Folder
If filePath <> "" Then
Set fo = fs.GetFolder(filePath)
Dim text As TextStream
For Each f In fo.Files
Sheet1.Range("A" & row).Value = f.Name
Set text = f.OpenAsTextStream()
While (Not text.AtEndOfLine)
Str1 = text.ReadLine()
If Left(Str1, 12) = "3:001:排料圖的ID" Then
Sheet1.Range("B" & row).Value = Right(Str1, Len(Str1) - InStr(1, Str1, " "))
End If
If Left(Str1, 12) = "3:002:排料圖的長度" Then
Sheet1.Range("C" & row).Value = Right(Str1, Len(Str1) - InStr(1, Str1, " "))
End If
If Left(Str1, 12) = "3:003:排料圖的寬度" Then
Sheet1.Range("D" & row).Value = Right(Str1, Len(Str1) - InStr(1, Str1, " "))
End If
If Left(Str1, 9) = "3:004:部件數" Then
Sheet1.Range("E" & row).Value = Right(Str1, Len(Str1) - InStr(1, Str1, " "))
End If
If Left(Str1, 10) = "3:005:剪裁時期" Then
Sheet1.Range("F" & row).Value = Trim(Right(Str1, Len(Str1) - InStr(1, Str1, " ")))
End If
If Left(Str1, 12) = "3:006:剪裁開始時間" Then
Sheet1.Range("G" & row).Value = Trim(Right(Str1, Len(Str1) - InStr(1, Str1, " ")))
End If
If Left(Str1, 12) = "3:007:剪裁結束時間" Then
Sheet1.Range("H" & row).Value = Trim(Right(Str1, Len(Str1) - InStr(1, Str1, " ")))
End If
If Left(Str1, 10) = "3:008:剪裁時間" Then
Sheet1.Range("I" & row).Value = Trim(Right(Str1, Len(Str1) - InStr(1, Str1, " ")))
End If
If Left(Str1, 12) = "3:009:平均剪裁速度" Then
Sheet1.Range("J" & row).Value = Right(Str1, Len(Str1) - InStr(1, Str1, " "))
End If
If Left(Str1, 10) = "3:010:剪裁距離" Then
Sheet1.Range("K" & row).Value = Right(Str1, Len(Str1) - InStr(1, Str1, " "))
End If
If Left(Str1, 14) = "3:011:刀片上升轉換角度" Then
Sheet1.Range("L" & row).Value = Right(Str1, Len(Str1) - InStr(1, Str1, " "))
End If
If Left(Str1, 13) = "3:012:刀具轉換的角度" Then
Sheet1.Range("M" & row).Value = Right(Str1, Len(Str1) - InStr(1, Str1, " "))
End If
If Left(Str1, 14) = "3:013:剪裁速度(高速)" Then
Sheet1.Range("N" & row).Value = Right(Str1, Len(Str1) - InStr(1, Str1, " "))
End If
If Left(Str1, 14) = "3:014:剪裁速度(低速)" Then
Sheet1.Range("O" & row).Value = Right(Str1, Len(Str1) - InStr(1, Str1, " "))
End If
If Left(Str1, 12) = "3:027:剪裁時間22" Then
Sheet1.Range("P" & row).Value = Trim(Right(Str1, Len(Str1) - InStr(1, Str1, " ")))
End If
If Left(Str1, 7) = "4:001:0" Then
Sheet1.Range("Q" & row).Value = Right(Str1, Len(Str1) - InStr(1, Str1, " "))
End If
Wend
row = row + 1
Next
nextFile:
End If
Range("C4:C30000").Select
Selection.NumberFormat = "0.00"
Range("D4:D30000").Select
Selection.NumberFormat = "0.00"
Range("E4:E30000").Select
Selection.NumberFormat = "0"
Range("F4:F30000").Select
Selection.NumberFormat = "YYYY/MM/DD"
Range("G4:G30000").Select
Selection.NumberFormat = "hh:mm:ss"
Range("H4:H30000").Select
Selection.NumberFormat = "hh:mm:ss"
Range("I4:I30000").Select
Selection.NumberFormat = "hh:mm:ss"
Range("J4:J30000").Select
Selection.NumberFormat = "0.00"
Range("K4:K30000").Select
Selection.NumberFormat = "0.00"
Range("L4:L30000").Select
Selection.NumberFormat = "0.00"
Range("M4:M30000").Select
Selection.NumberFormat = "0.00"
Range("N4:N30000").Select
Selection.NumberFormat = "0"
Range("O4:O30000").Select
Selection.NumberFormat = "0"
Range("p4:P30000").Select
Selection.NumberFormat = "hh:mm:ss"
Range("Q4:Q30000").Select
Selection.NumberFormat = "0"
Range("R4:S1000").Clear
Range("A3:A3").Select
MsgBox "The folder's Marker Reports Run Finished檔案夾中的所有檔案已經運行完成"
End Sub
uj5u.com熱心網友回復:
附件檔案怎么上傳?uj5u.com熱心網友回復:
wm0411666你發我檔案看下吧
uj5u.com熱心網友回復:
有檔案可以看看不?uj5u.com熱心網友回復:
原代碼End If
Wend
row = row + 1
Next
改成
End If
row = row + 1
Wend
Next
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/7355.html
標籤:VBA
上一篇:VB
下一篇:VBA 代碼 運行 卡死
