標題:
請問要如何把A1、A2、A3合併至 C1, 文字內容字型、顏色不變。
[打印本頁]
作者:
oiggu
時間:
2011-10-27 14:19
標題:
請問要如何把A1、A2、A3合併至 C1, 文字內容字型、顏色不變。
各位好:
請問要如何把A1、A2、A3合併至 C1, 文字內容字型、顏色不變。
VBA 要如何編寫
SUB TEST()
[C1]=[A1]&[A2]&[A3]
END SUB
所顯示之結果只有字串之合併,顏色屬性皆改變。
[attach]8355[/attach]
作者:
GBKEE
時間:
2011-10-27 16:05
回復
1#
oiggu
Sub Ex()
Dim R As Range, i As Integer, ii As Integer
[C1].Clear
[C1] = Join(Application.WorksheetFunction.Transpose([A1:A3]), Chr(10))
i = 1
For Each R In [A1:A3]
For ii = 1 To Len(R)
With R.Characters(Start:=ii, Length:=1).Font
[C1].Characters(Start:=i, Length:=1).Font.Name = .Name
[C1].Characters(Start:=i, Length:=1).Font.FontStyle = .FontStyle
[C1].Characters(Start:=i, Length:=1).Font.Size = .Size
[C1].Characters(Start:=i, Length:=1).Font.Strikethrough = .Strikethrough
[C1].Characters(Start:=i, Length:=1).Font.Superscript = .Superscript
[C1].Characters(Start:=i, Length:=1).Font.Subscript = .Subscript
[C1].Characters(Start:=i, Length:=1).Font.OutlineFont = .OutlineFont
[C1].Characters(Start:=i, Length:=1).Font.Shadow = .Shadow
[C1].Characters(Start:=i, Length:=1).Font.Underline = .Underline
[C1].Characters(Start:=i, Length:=1).Font.ColorIndex = .ColorIndex
End With
i = i + 1
Next
i = i + 1
Next
End Sub
複製代碼
作者:
luhpro
時間:
2011-10-27 21:46
回復
2#
GBKEE
也可以簡化成以下這樣 :
Sub Ex()
Dim R As Range, i As Integer, ii As Integer
Dim fS As Font, fT As Font
[C1].Clear
[C1] = Join(Application.WorksheetFunction.Transpose([A1:A3]), Chr(10))
i = 1
For Each R In [A1:A3]
For ii = 1 To Len(R)
Set fS = R.Characters(Start:=ii, Length:=1).Font
Set fT = [C1].Characters(Start:=i, Length:=1).Font
With fS
fT.Name = .Name
fT.FontStyle = .FontStyle
fT.Size = .Size
fT.Strikethrough = .Strikethrough
fT.Superscript = .Superscript
fT.Subscript = .Subscript
fT.OutlineFont = .OutlineFont
fT.Shadow = .Shadow
fT.Underline = .Underline
fT.ColorIndex = .ColorIndex
End With
i = i + 1
Next
i = i + 1
Next
End Sub
複製代碼
作者:
oiggu
時間:
2011-10-28 08:09
謝謝 GBKEE、 luhpro 功力太強了,經測試都可使用。
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)