简体   繁体   English

换行单元格文本而不将任何单词字符分成两行

[英]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.

相关问题 在 Excel 检查两个单元格中的短语,如果在两个单元格中找到任何列出的单词,则需要在另一个单元格中添加该单词。 对整列重复此操作 - In Excel Check phrases in two cell and in the two cell if any listed word found,need to add the word in another cell. repeat this for entire column 在 Excel 中多行多次提取两个字符之间的文本 - Extract text between two characters multiple times on multiple lines in Excel 如何从包装的单元格中获取前两行文本? - How to get first two lines of text from a wraped cell? 对于 excel 单元(xlsx 文件格式),哪些字符会调用 alt+enter? (wrap_text 不起作用) - What characters invokes alt+enter for an excel cell (xlsx file format)? (wrap_text does NOT work) 将文本从Excel复制到单词作为没有单元格边框的句子 - To copy text from excel to word as sentence without cell borders 计算单元格中的文本行 - Count lines of text in a cell 如何使用VBA代码将带有项目符号,粗体字符和换行符的文本粘贴到单个excel单元格中? - How to paste text with bullets, bold characters and break lines into a single excel cell using VBA code? 查找在列中包含文本且在字符串的前6个字符中不包含某些单词的单元格 - Find Cell containing text in column and does NOT contain certain word in first 6 characters of string 在不换行的情况下收缩文本框中的文本 - Shrink Text in Textbox without Wrap 多行文本进入一个单元格 - Multiple lines of text into one cell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM