【发布时间】:2018-09-05 17:37:55
【问题描述】:
我正在使用下面的宏将选定范围(在 Excel 中)写入 .txt 文件。
Sub ExportTXT()
Dim myFile As String
Dim rng As Range
Dim cellValue As Variant
Dim i As Integer
Dim j As Integer
myFile = Application.DefaultFilePath & "\sales.txt"
Set rng = Range(Cells(1, 1), Cells(10, 4))
Open myFile For Output As #1
For i = 1 To rng.Rows.Count
For j = 1 To rng.Columns.Count
cellValue = rng.Cells(i, j).Value
If j = rng.Columns.Count Then
Write #1, cellValue
Else
Write #1, cellValue,
End If
Next j
Next i
Close #1
End Sub
如何跳过空白行?
我尝试过使用 Isempty(cellValue) = True ** 和空字符串 **"" 条件语句。
关于如何检查 cellValue 内容以查看它是否为空并仅写入包含数据的行的任何想法。
【问题讨论】: