连接 2 个字符串和上标 [英] Concatenation of 2 strings and superscript

查看:30
本文介绍了连接 2 个字符串和上标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是我有 3 个单元格 A1 、 B1 和 C1 ;A1 包含一个数字, B1 是一个字符串, C1 包含 B1 和 A1 的串联.假设 A1 包含值 1 并且 B1 包含值 "Test" ;我希望 C1 包含 Test1 但以 1 作为上标.这是我编写的代码,但不起作用:

My issue is that i have 3 cells A1 , B1 and C1 ; A1 contains a number, B1 a string and C1 contains the concatenation of B1 and A1 . Let's say A1 contains the value 1 and B1 the value "Test" ; I want C1 to Contain Test1 but with 1 as a superscript . Here's the code i've written but that isn't working :

Sub exposantmiseenforme()

    Dim i As Integer
    Dim C As Range
    Dim l As Integer

    l = Len(Range("B1"))
    C = Range("C1")

    With C.Characters(Start:=l, Length:=l + 1).Font
        .Name = "Calibri"
        .FontStyle = "Normal"
        .Size = 11
        .Strikethrough = False
        .Superscript = True
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ThemeColor = xlThemeColorLight1
        .TintAndShade = 0
        .ThemeFont = xlThemeFontMinor
    End With

End Sub

提前感谢您的帮助!

推荐答案

您可以尝试以下操作(假设您有更多行,而不仅仅是单元格 A1 和 B1):

You could try the following (assuming you have more rows than just cells A1 & B1):

示例数据:

代码:

Sub SuperScriptTxt()

Dim rng As Range, cl As Range, lr As Long
With ThisWorkbook.Sheets("Sheet1") 'Change accordingly
    lr = .Cells(.Rows.Count, "A").End(xlUp).Row
    Set rng = .Range("C2:C" & lr)
    For Each cl In rng
        cl.Value = cl.Offset(, -2) & cl.Offset(, -1) 'Leave out this line, if concatenated values are actually already in place.
        cl.Characters(Len(cl.Offset(, -2)) + 1, Len(cl.Offset(, -1))).Font.SuperScript = True
    Next cl
End With

End Sub

结果:

这篇关于连接 2 个字符串和上标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆