[英]Wrap cell text without dividing any word characters into two lines
As you see on the above picture, I need to wrap the cell text without dividing any word characters into two lines.正如您在上图中看到的,我需要将单元格文本换行,而不将任何单词字符分成两行。
Also I want to preserve the column width.我也想保留列宽。
I made the issue words in bold to illustrate the problem.我把问题用粗体字写成粗体来说明问题。
These are initial cells text without any wrapping:这些是没有任何换行的初始单元格文本:
Pressure Vessel压力容器
Infra, Platfrom Facilities基础设施、平台设施
Follow up Clamps, Weak Points跟进夹子,弱点
My actual dataset is 11k rows.我的实际数据集是 11k 行。 grateful for all your help.
感谢您的所有帮助。
Sub Wraptext()
Range("A2:A4").Wraptext = True
End Sub
The idea of this answer is fully go to @Ike and @Brennan.这个答案的想法完全是 go 到@Ike 和@Brennan。
I just convert it to VBA code to make it easier for anyone have the same issue.我只是将其转换为 VBA 代码,以方便遇到相同问题的任何人。
Sub Replace_non_breaking_space()
'Chr(160) is the (non_breaking_Space)
'Chr(32) is the normal Space
Dim ws As Worksheet
Set ws = ActiveSheet 'adapt to your need
Dim cel As Range
For Each cel In ws.Range("A2:A4")
cel = Application.Trim(Replace(cel, Chr(160), Chr(32)))
Next cel
ws.Range("A2:A4").WrapText = True
End Sub
Your data might have 'bad spaces' in it, meaning Excel isn't correctly recognizing the space characters as the preferred place to split the text up.您的数据中可能有“坏空格”,这意味着 Excel 没有正确地将空格字符识别为分割文本的首选位置。 Try copying the space character between Pressure and Vessel, then find and replace with a normal space character.
尝试复制 Pressure 和 Vessel 之间的空格字符,然后查找并替换为正常的空格字符。
Edit: Now that you know your spaces are 160, do a find a replace on alt+0160 with alt+0032编辑:既然您知道您的空间是 160,请在 alt+0160 上查找替换为 alt+0032
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.