excel - vbNewLine 直到双击才反映?
问题描述
我有一些通过我的代码合并的单元格,
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
无济于事。
谢谢!
解决方案
我试图重现您遇到的问题,并且在将符号与 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
推荐阅读
- flutter - Flutter 在更新时删除 Hive 数据库
- javascript - 来自 JavaScript Fetch 响应的协议版本
- css - 保存在浏览器缓存中的网站文件阻止显示更改
- python - 递归合并排序无法正常工作
- arrays - 使用 array_name 与 &array_name 的地址之间的区别?
- javascript - Joi.validate 不是一个函数
- linux - 尝试在centos8上使用kickstart文件安装VM时不断收到内核错误
- laravel - 带有 Laravel Passport 的开源应用程序。如何保护客户机密?
- excel - vba 循环遍历工作簿
- vue.js - Vue Formulate 上 excel 文件的 MIME 验证是什么?