如何将 Excel 语句的大小减小到 txt 文件并跳过没有数据的空单元格。下面是我的代码的一小部分,但至少有 204 行长并且非常冗余。
Private Sub CommandButton1_Click()
Open (Cells(3, 4)) For Output As #1
If Len(Cells(5, 6)) <> 0 Then Print #1, Replace(Cells(5, 2), "-", ""); ","; Trim(Cells(5, 6)); ","; Trim(Cells(5, 8))
If Len(Cells(6, 6)) <> 0 Then Print #1, Replace(Cells(6, 2), "-", ""); ","; Trim(Cells(6, 6)); ","; Trim(Cells(6, 8))
If Len(Cells(7, 6)) <> 0 Then Print #1, Replace(Cells(7, 2), "-", ""); ","; Trim(Cells(7, 6)); ","; Trim(Cells(7, 8))
If Len(Cells(8, 6)) <> 0 Then Print #1, Replace(Cells(8, 2), "-", ""); ","; Trim(Cells(8, 6)); ","; Trim(Cells(8, 8))
If Len(Cells(9, 6)) <> 0 Then Print #1, Replace(Cells(9, 2), "-", ""); ","; Trim(Cells(9, 6)); ","; Trim(Cells(9, 8))
If Len(Cells(10, 6)) <> 0 Then Print #1, Replace(Cells(10, 2), "-", ""); ","; Trim(Cells(10, 6)); ","; Trim(Cells(10, 8))
End Sub