我想要两个字体放在同一个单元格里。第二行是价格和度量单位(例如ea、dz、cs、pk)。
当我在一个单元格上工作时,activeCell.character
正在寻找第一个字体的开始和第二个字体的开始。
由于价格的变化是大小从3个数字,包括小数后的小数位到4,5和6,这种方法是行不通的。
我需要一些东西,将单元格作为一种字体,然后在小数点的右边3位“。改变字体。
Sub TwoFonts2()
Dim MyPos, SearchChar
SearchChar = "."
Rows("2:2").Select
With ActiveCell.Characters(Start:=1, Length:=8).Font
.Name = "ITC Avant Garde Std Bk"
.FontStyle = "Bold"
.Size = 26
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With MyPos = (InStr(SearchChar, x, " ") + 3)
.Name = "ITC Avant Garde Std Bk"
.FontStyle = "Bold"
.Size = 14
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
End Sub
发布于 2022-02-07 14:26:24
请试试下一条路。它接受数字前面的空格,这是必须有一个小数点分隔符的。最后一个空格后的字符串(对于第二个字体)可能有任意数量的字符。如果只有一个空格,在最后一个小字体字符之前,代码可以简化,直接返回空格位置:
Sub SplitCharactersFonts()
Dim x As String, secF As Long
x = ActiveCell.Value
secF = InStr(InStr(x, "."), x, " ") + 1 'find space starting from dot position
With ActiveCell.Characters(1, secF - 1).Font
.size = 26
'do watever you need with the first part
End With
With ActiveCell.Characters(secF, Len(x)).Font
.size = 14
'do whatever you need with the second part
End With
End Sub
https://stackoverflow.com/questions/71019432
复制相似问题