我是新手,但我需要帮助! 我创建了一个电子表格,打算将其导出为 .txt 文件,以便上传到我的薪资软件。 该代码运行良好,但我不知道如何让它跳过空白行。 我希望它在 A 列中查找,如果 d 列中的相应单元格为空,则需要跳过它并继续循环。 到目前为止还没有任何效果...
这是我当前的代码。 我不知道要添加什么,甚至不知道在哪里添加。 除了跳过空白之外,这适用于我需要的一切。
Dim thisWS As Worksheet
Set thisWS = Sheet1
Dim LastRow As Long
Dim workArea As Range
With thisWS
LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
Set workArea = .Range(.Cells(2, 2), .Cells(LastRow, 7))
End With
Dim saveFileName As String
saveFileName = Application.GetSaveAsFilename("2024Testing", "text files (*.txt), *.txt")
Open saveFileName For Output As #1
Dim i As Integer
Dim j As Integer
Dim lineText As String
For i = 1 To workArea.Rows.Count
For j = 1 To workArea.Columns.Count
lineText = IIf(j = 1, "", lineText & ",") & workArea.Cells(i, j)
Next j
lineText = Left$(lineText, Len(lineText) - 2)
Print #1, lineText
Next i
Close #1
MsgBox "Bonus Import File Created"
End Sub
这是输出...带有零的行是我需要跳过的。
BRA29001,BONUS,3201,12132024
BUN29001,BONUS,0,12132024
BYN29001,BONUS,3201,12132024
试试这个:
'your code
For j = 1 To workArea.Columns.Count
if workArea.Cells(i, "D").value > 0 then
lineText = IIf(j = 1, "", lineText & ",") & workArea.Cells(i, j)
end if
Next j
'your code