复制范围到文本文件时跳过空白行

时间:2013-11-25 12:34:27

标签: excel excel-vba vba

我的程序复制 Lg1 行将Excel范围形成为文本文件。我想阻止将任何 空白 行表单复制到文本文件中。每行的第一个单元格包含以下公式:=IF(L39C7=0;"";L15C20)。如您所见,单元格为空 “” ,或包含L15C20值。

编辑:这是一个完整的行。所有行都有相同的内容:[=IF(L39C7=0;"";L15C20)],[=IF(LC(-1)="";"";IF(L39C7<0;"…";"5272"))],[=IF(LC(-2)="";"";IF(L41C7<0;"…";"2302"))],[=IF(LC(-3)="";"";"salaire")],[=IF(LC(-4)="";"";"0")]

以下是我的代码的一部分:

With ws
Set RngSelect = .Range(Cells(FirstRow, FirstCol), Cells(31, LastCol)) 
End with
With RngSelect
For Lg1 = 1 To (LastRow - FirstRow + 1)
    If .Cells(Lg1,1).Value <> "" Then  'Here is my issue
    Txt = Txt & vbCrLf & Join$(Application.Transpose(Application.Transpose(.Rows(Lg1).Value)), vbTab)
    Next
    End If
End With
Lg2 = FreeFile()
Open FilePath For Append As #Lg2
Print #Lg2, Mid$(Txt, Len(vbCrLf) + 1)
Close Lg2

我试过没有成功的各种测试来评估If cell&lt;&gt; “”但在我的文本文件中保持空白行。我该怎么写才能解决我的问题?

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

最好以这种方式检查空白(此处为您范围内的第一列):

If Len(.Cells(Lg1, 1).Value) > 0 Then
相关问题