我想将数据从 excel 复制到 csv 但似乎找不到正确的逻辑。以下是我想要复制数据的方式。例如,我想将 excel 的单元格 D4 中的数据复制到 csv 中的 A4 中。我想重复此操作,直到 D 列中的单元格为空。
"Excel ---> CSV
"D4-->A4
"F4&G4-->B4
"K4-->E4
"L4-->F4
"N4-->G4
"P4-->I4
很抱歉在我刚开始编写宏时问了这样一个基本问题。以下是我目前的代码。这会创建 csv 文件,但不会填充我需要的数据。
Sub csvfile()
Dim fs As Object, a As Object, i As Integer, s As String, t As String, l As String, mn As String
Set fs = CreateObject("Scripting.FileSystemObject")
sUser = Environ("username")
Set a = fs.CreateTextFile("S:\ics\jellybean\" & sUser & ".csv", True)
For r = 4 To Range("A65536").End(xlUp).Row
s = ""
c = 6
While Not IsEmpty(Cells(r, c))
s = s & Cells(r, c) & ","
c = c + 1
Wend
a.writeline s 'write line
Next r
End Sub