首页 > 解决方案 > 合并来自不同单元格的文本并保持格式

问题描述

是否可以将信息从多个单元格复制到一个单元格并保持格式?例如,我有 A1=Hello (Green, bold font), A2, World (red font)

想要 B2=Hello World(用不同颜色的单词)。

在 Google 表格中寻找解决方案,但作为替代方案,Excel 也可以使用

标签: vbagoogle-apps-script

解决方案


例如,我的 activecell 有单词“bankeris”,所以我将前 3 个字母设为一种颜色,另外 3 个字母设为另一种颜色。此代码是通过“宏录制”。所以复制/粘贴也会这样做。

With ActiveCell.Characters(Start:=1, Length:=3).Font
        .Name = "Calibri"
        .FontStyle = "Regular"
        .Size = 11
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .Color = -16776961
        .TintAndShade = 0
        .ThemeFont = xlThemeFontMinor
    End With
    With ActiveCell.Characters(Start:=4, Length:=3).Font
        .Name = "Calibri"
        .FontStyle = "Regular"
        .Size = 11
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ThemeColor = xlThemeColorAccent6
        .TintAndShade = -0.249977111117893
        .ThemeFont = xlThemeFontMinor
    End With

推荐阅读