简体   繁体   English

宏以验证选定的非空白单元格-Excel VBA

[英]Macro to validate selected non-blank cells - Excel VBA

I'm trying to add separator in each cell. 我正在尝试在每个单元格中添加分隔符。

But this code bellow adding seperator on all cells empty or not, I need seperator only on Not empty cells. 但是下面的代码在所有空单元格上添加了分隔符,我只需要在非空单元格上添加分隔符。

Could you help me, tks a lot 您能帮我很多吗

    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

Can you try to validate cell values for non-blanks? 您可以尝试验证非空白的单元格值吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM