謝謝前輩發表此主題
Option Explicit
Sub TEST()
Application.DisplayAlerts = False
Dim i&, xR As Range, N&
Set xR = [A2]
For i = 2 To [A65536].End(xlUp).Row + 1
If Cells(i, 1) <> xR Then
If N > 1 Then xR.Resize(N).Merge
Set xR = Cells(i, 1)
N = 0
End If
N = N + 1
Next
End Sub作者: 198188 時間: 2024-3-1 13:39
Option Explicit
Sub TEST()
Application.DisplayAlerts = False
Dim i&, xR As Range, N&
Set xR = [A2]
For i = 2 To [A65536].End(xlUp).Row + 1
If Cells(i, 1) <> xR Then
If N > 1 Then xR.Resize(N).Merge
xR(N, 3) = "=SUM(" & xR(1, 2).Address & ":" & xR(N, 2).Address & ")"
Set xR = Cells(i, 1)
N = 0
End If
N = N + 1
Next
End Sub作者: 198188 時間: 2024-3-1 15:04
Option Explicit
Sub TEST_1()
Dim i&
For i = 2 To Intersect(ActiveSheet.UsedRange, [A:A]).Rows.Count
With Cells(i, 1).MergeArea
.UnMerge
.Value = Cells(i, 1)
i = i + .Count - 1
End With
Next
End Sub