Excel VBA:Range.Characters.Delete 255string

任何方式来删除给定单元格中255+字符的string,同时保持格式?

例:

Range("A1").value = "Lathe-CNC-Primary1 | Inspection-In Process1 | OV - Heat Treat0 | Deburring1 | Lathe-CNC-Primary0 | Honing0 | Lathe-CNC-Primary0 | Deburring1 | Inspection-In Process1 | OV - FPI0 | Inspection-In Process1 | OV - Nitride0 | Inspection-In Process1 | Grinding Thru Feed1 | Inspection-In Process0 | 0V - Coating0 | Inspection-Final0" Range("A1").Characters(Start:=1, Length:=17).font.bold = True Range("A1").Characters(Start:=17, Length:=1).delete 'Does Nothing 

我在这个string中使用了1和0(来自SQL语句)来格式化它所连接的单词,然后删除1或0。

Range(“A1”)中string的所需结果:

车床-CNC-主 | | 检查过程1 | OV – 热处理0 | 去毛刺1 | 车床-CNC-Primary0 | Honing0 | 车床-CNC-Primary0 | 去毛刺1 | 检查过程1 | OV – FPI0 | 检查过程1 | OV – 氮化物0 | 检查过程1 | 磨通过Feed1 | 检查过程0 | 0V – 涂层0 | 免检Final0

谢谢,乔希

不知道你的实际目标是什么

你也可以

  • 格式化后使用Replace()方法:

     With Range("A1") Replace what:="1 |",replacement:=" |", LookAT:=xlPart Replace what:="0 |",replacement:=" |", LookAT:=xlPart End With 
  • 使用Mid()函数:

     With Range("A1") .Value = Mid(.Value, Start:=1, Length:=17) & Mid(.Value, Start:=18) '<--| "deletes" character in position 18 End With