这是一个奇怪的具体问题。假设我有一个产生值为 0 的单元格。我正在将其写入文本文件。
当我写它而不是 0 时,我希望有四个空格(它本质上是 null 的视觉占位符)。
这条线的问题:
cellValue = Replace(cellValue, 0, " ")
这倾向于用四个空格替换所有零。有人知道如何解决这个问题吗?我将不胜感激。
样本输入:
0 | 100 | 48
样本输出:
____10048 (Underscores are spaces).
到目前为止我所拥有的:
Dim myFile As String, rng As Range, cellValue As Variant, I As Integer, j As Integer
myFile = Application.DefaultFilePath & "\test_data_output.txt"
Set rng = Selection
Open myFile For Output As #1
For I = 1 To rng.Rows.Count
For j = 1 To rng.Columns.Count
cellValue = Replace(cellValue, 0, " ")
cellValue = cellValue + CStr(rng.Cells(I, j).Value)
If j = rng.Columns.Count Then
Print #1, cellValue
End If
Next j
cellValue = ""
Next I
Close #1
- - - - - - - - - - - - - - - - -更新 - - - - - - - - ----------------------
所以我们只是决定在 isBLANK 条件下做一个 excel 表,如果它是假的,则显示 4 个空格。现在应该可以了。感谢所有的帮助。它本质上是一组空白单元格,并被转移到一张新表上。因此,由于某种原因,它总是显示 0 以显示其空白。我们决定 if else 是最好的。
Excel 代码:
=IF(ISBLANK('OurSheetName'!I7)," ",'OurSheetName'!I8)