【发布时间】:2014-06-05 15:34:59
【问题描述】:
我正在尝试在 VBA 中创建一个 CSV 输出文件,但我似乎无法获得它。我需要遍历电子表格并根据列 D 中是否有“1”从“I”列中提取数字。然后我想将“I”列的内容粘贴到 CSV 输出文件的“A”列中。有人可以帮我完成这个吗?我想合并以下所有内容:
Sub Test()
Dim FileNum, bOutputLine, bFile As String
Dim bOUTPUT, iRow As Integer
bOUTPUT = FreeFile 'Define bOUTPUT as a FreeFile
bFile = "C:\Desktop\Test.csv" 'set the filepath equal to a string
For iRow = 2 To ActiveSheet.UsedRange.Rows.Count
If Trim(range("D" & iRow)) <> "" Then
FileNum = Trim(range("I" & iRow))
End If
Next
Open bFile For Output As bOUTPUT 'Open the file
bOutputLine = FileNum
Print #bOUTPUT, bOutputLine
Close #bOUTPUT 'Close the file
End Sub
【问题讨论】: