0

我正在尝试在每个单元格中添加分隔符。

但是这段代码在所有单元格上添加分隔符是否为空,我只在非空单元格上需要分隔符。

你能帮我吗,tks很多

    Dim Range As Object, Line As Object, Cell As Object
    Dim StrTemp, chemin As String
    Dim Separateur As String

    Separateur = ","
    'WBDest.Activate
    Set Range = Worksheets(1).Columns(i)
    'Set Range = Worksheets(1).Columns(i).SpecialCells(xlCellTypeBlanks) ' Not work

    Open "C:\export\" + Str(i) + ".csv" For Output As #1
    For Each Line In Range.Rows
        StrTemp = ""
        For Each Cell In Line.Cells
            StrTemp = StrTemp & CStr _
            (Cell.Text) & Separateur
        Next
        Print #1, StrTemp '= " "
    Next
    Close
4

1 回答 1

0

您可以尝试验证非空白的单元格值吗?

For Each Line In Range.Rows
    StrTemp = ""
    For Each Cell in Line.Cells
       If Cell.Text <> "" then                     'validate for non-blanks
            StrTemp = StrTemp & CStr _
            (Cell.Text) & Separateur
       End if
    Next
        Print #1, StrTemp '= " "
 Next
于 2012-11-25T12:13:14.573 回答