简体   繁体   English

excel vba选择单元格中的倒数第二个字符

[英]excel vba select second to last character in a cell

I thought this would be simple but can't find the solution anywhere!我认为这很简单,但在任何地方都找不到解决方案! I am writing a macro to insert a red tick (or down arrow) after the existing text in a cell.我正在编写一个宏以在单元格中的现有文本后插入红色勾号(或向下箭头)。

 ActiveCell.FormulaR1C1 = ActiveCell & " P "

The P needs to be formatted bold, red and Wingdings 2. It needs a space after it in case text is added at the end in the future. P 需要格式化为粗体、红色和 Wingdings 2。它后面需要一个空格,以防将来在末尾添加文本。

No problem if it is before the text:如果在文本之前没问题:

With ActiveCell.Characters(Start:=2, length:=1).Font

How can I select it when it is the second to last character in the cell?当它是单元格中的倒数第二个字符时,如何选择它?

(Or is there any other way to achieve this?) (或者有没有其他方法可以实现这一目标?)

Try this:试试这个:

With ActiveCell.Characters(ActiveCell.Characters.count - 1, 1).Font
  .name = "Wingdings 2"
  .Bold = True
End With

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM