
ALT+F11打开工程对话框
然后复制以下代码粘贴
Sub UnmergeAndDistribute()
Dim rng As Range
Dim cell As Range
Dim total As Double
Dim count As Integer
Dim avg As Double
' 设置要处理的列范围
Set rng = Range("A1:A" & Cells(Rows.count, "A").End(xlUp).Row)
' 遍历A列中的每一个单元格
For Each cell In rng
' 检查单元格是否是合并单元格的一部分
If cell.MergeCells Then
' 计算合并单元格的总和
total = Application.WorksheetFunction.Sum(cell.MergeArea)
' 计算合并单元格的数量
count = cell.MergeArea.count
' 计算平均值
avg = total / count
' 取消合并单元格
cell.MergeArea.UnMerge
' 将平均值分配到每一个单元格中
cell.Resize(count, 1).Value = avg
End If
Next cell
End Sub