用这个就不要改代码了
Sub retest()
Dim a&, b&, c&, d&, arr, brr, T&, i&, j&, rg As Range, rng As Range, x As Integer
Set rg = Application.InputBox("请选择数据源单元格区域", "选取提示", , , , , , 8)
Set rng = Application.InputBox("请选择输出结果单元格区域", "选取提示", , , , , , 8)
rng.ClearContents
arr = rg
a = rg.Row
b = rg.Rows.Count
c = rg.Column
d = rg.Columns.Count
ReDim brr(1 To UBound(arr), 1 To 1)
For i = 1 To UBound(arr)
brr(i, 1) = Join(Application.Index(arr, i), " ")
Next i
rng = brr
T = 1
For i = 1 To UBound(arr)
For j = 1 To UBound(arr, 2)
Cells(a + i - 1, c + d + 1).Characters(Start:=T, Length:=Len(arr(i, j))).Font.Color = Cells(a + i - 1, j + c - 1).Font.Color
T = Len(arr(i, j)) + 3 + T
Next j
T = 1
Next
End Sub
|