|
楼主 |
发表于 2018-8-11 13:55
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
找到解决方案了
Sub 提取CSV()
strfile = Application.GetOpenFilename("EXCEL文档(*.CSV*),", , "请选择记录文件")
If strfile = "" Then Exit Sub
With Workbooks.Open(strfile)
ar = .Sheets(1).UsedRange
L1 = .Sheets(1).Rows(1).Find("Designator", , , xlWhole).Column
L2 = .Sheets(1).Rows(1).Find("Footprint", , , xlWhole).Column
L3 = .Sheets(1).Rows(1).Find("Mid X", , , xlWhole).Column
L4 = .Sheets(1).Rows(1).Find("Mid Y", , , xlWhole).Column
L5 = .Sheets(1).Rows(1).Find("Rotation", , , xlWhole).Column
.Close 0
End With
ReDim br(1 To 1000, 1 To 5)
For i = 2 To UBound(ar)
If Len(ar(i, L1)) Then
If Right(ar(i, L1), 1) = "," Then x = Left(ar(i, L1), Len(ar(i, L1)) - 1) Else x = ar(i, L1)
n = n + 1
br(n, 1) = ar(i, L1)
br(n, 2) = ar(i, L2)
br(n, 3) = ar(i, L3)
br(n, 4) = ar(i, L4)
br(n, 5) = ar(i, L5)
End If
Next
Cells.ClearContents
Range("a3").Resize(n, 5) = br
End Sub |
|