我正在尝试在每个单元格中添加分隔符。
但是这段代码在所有单元格上都添加了分隔符,或者没有,我只需要在非空单元格中使用分隔符。
你能帮助我吗,很多人
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
答案 0 :(得分: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