我通过代码合并了一些单元格,
If InStr(outSht.Cells(lRow2, 3), entry.Offset(, 1)) = 1 Then 'does name exist?
outSht.Cells(lRow2, 4) = outSht.Cells(lRow2, 4) & vbNewLine & entry.Offset(, 1)
End If
outSht.Cells(lRow2, 6) = outSht.Cells(lRow2, 6) & vbNewLine & entry.Offset(, -2)
outSht.Cells(lRow2, 7) = outSht.Cells(lRow2, 7) + entry.Offset(, 2)
但是,它最终都在同一行上,直到我手动双击该单元格。这是一个显示正在发生的事情的快速 gif。
https://gyazo.com/eb50d0ecb25e022b53643a65917ac835
我是否遗漏了一些非常基本的东西?我试过 Chr(10)
、Chr(13) & Chr(10)
和 vbCrLf
都无济于事。
谢谢!
答案 0 :(得分:0)
我尝试重现您遇到的问题,并且在将符号与 ACSII 13 一起使用时也有类似的效果。将字符与 ASCII 10 一起使用时,一切正常。 尝试强制使用 .WrapText = True
属性。以下是调查问题的测试代码:
Sub test1()
a = Array(vbLf, vbCr, vbCrLf, vbNewLine, Chr(10), Chr(13))
ActiveSheet.Cells.Delete ' clear the Worksheet
With ActiveSheet.Range("A1")
For i = 0 To UBound(a)
txt = ""
For s = 1 To Len(a(i))
txt = txt & "," & Asc(Mid(a(i), s, 1))
Next
txt = Mid(txt, 2)
.Offset(i).WrapText = False
.Offset(i).Value = "A1-101222" & a(i) & "A1-103209" & a(i) & "A1-101406"
.Offset(i, 1).Value = "Used " & i & " symbol(s) ASCII[" & txt _
& "] and final WrapText is: " & .Offset(i).WrapText
Next
End With
With ActiveSheet.UsedRange
.EntireColumn.AutoFit
.EntireRow.AutoFit
End With
End Sub
<块引用>