英文:
Excel VBA text import not formatting line-breaks correctly until double-clicking on cell
问题
我有一个VBA例程,导入一个CSV文件,然后将其适配到特定表格的正确日期。导入功能正常,但换行符不显示正确,即使在公式栏中显示正确。
如果你双击单元格,格式就会显示正确,但表格中有很多行,我不想为每个单元格单独操作。
有人能解释为什么会发生这种情况吗?是否有一种特殊的VBA输入文本到单元格的方法?还是在导入结束时需要添加一个命令?
我正在使用自动换行和自动调整行高。
这是我输入文本到单元格的方式。
英文:
I have a VBA routine that imports a CSV and then fits it to a specific table for the correct dates. The import works correctly, but the line-breaks do not display correctly, even though they are displayed correctly in the formula bar.
If you double-click the cell then the formatting displays correctly, but there are many lines within the table and I do not want to have to do it for each cell individually.
Can anyone explain why this is happening, is there a special way to enter the text into the cell with VBA? Or is there a command that I need to add at the end of the import?
I am using wordwrap and also auto row-height.
This is how I am inputting the text into the cells.
ws.Range("E" & LineRow).value = ReplaceCharacters(LineItems(1))
ws.Range("F" & LineRow).value = ReplaceCharacters(LineItems(2))
ws.Range("G" & LineRow).value = ReplaceCharacters(LineItems(3))
ws.Range("H" & LineRow).value = ReplaceCharacters(LineItems(4))
ws.Range("I" & LineRow).value = ReplaceCharacters(LineItems(5))
ws.Range("J" & LineRow).value = ReplaceCharacters(LineItems(6))
ws.Range("K" & LineRow).value = ReplaceCharacters(LineItems(7))
ws.Range("L" & LineRow).value = ReplaceCharacters(LineItems(8))
This is how the text appears in the table upon input.
And this is how it appears in the formula bar.
Once I double-click the cell, this is how the cell appears (which is correct).
答案1
得分: 3
ws.Range("E" & LineRow).value = Replace(ReplaceCharacters(LineItems(1)), vbCr, vbCrLf, 1, , vbBinaryCompare)或在内部修改ReplaceCharacters函数以进行替换。
英文:
....
ws.Range("E" & LineRow).value = Replace(ReplaceCharacters(LineItems(1)), vbCr, vbCrLf, 1, , vbBinaryCompare)
....
or modify internally the ReplaceCharacters function, to do the replacement.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论