VBA - 转换单元格中的指定字符为下标sub_script格式

在学习Verilog中需要用带下标符号来表示建立时间和保持时间等参数。excel中输入比较麻烦,需要选中字符后,再选择字体中的下标选项。所以做了这个VBA来实现下标转换功能。

Sub sub_script()
Dim str_len
Dim str_num
Dim str_sta

str_num = Application.InputBox("From end of the string,enter the number of character to be processed", "Sub script", 2, Type:=1) '使用inputbox输入希望处理的字符,从字符串末尾开始从右到左计算个数
str_len = ActiveCell.Characters.Count '字符宽度
str_sta = str_len - str_num + 1 '将处理的第一个字符的位置

For str_sub = str_sta To str_len '从设定处理的第一个字符开始,逐个处理字符
    With ActiveCell.Characters(str_sub, 1).Font '单独处理字串中的指定字符
        .Superscript = False '字符作为上标
        .Subscript = True    '字符作为下标
    End With
Next
End Sub

Sub super_script()
Dim str_len
Dim str_num
Dim str_sta

str_num = Application.InputBox("From end of the string,enter the number of character to be processed", "Sub script", 2, Type:=1)
str_len = ActiveCell
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值