如何使用VBA在excel中定位"alternatively"的"different size merged cells"中添加序列号?

How to add serial number in "different size merged cells" which are positioned "alternatively" in excel using VBA?

如图所示,我试图在备用合并单元格中以递增顺序填充数字,尺寸不同。所以,我无法使用excel的自动填充功能。但我想要一个宏,这样我每次只需按一次按钮就可以做到。
注意我只想要使用范围内的数字。

我自己做了很多尝试,但我现在卡住了...请帮助初学者,这是我在 VBA.

的第三天

这应该能满足您的需求。

它会忽略未合并的单元格,我在你的屏幕截图中没有看到任何需要数字且未合并的单元格,所以这应该不是问题。

它使用 B 列找出数据的最后一行。

    Dim i As Long
    Dim lr As Long
    Dim counter As Long
    counter = 1
    With Sheet1 'Change to whatever your sheets code name is
        lr = .Cells(.Rows.Count, 2).End(xlUp).Row 'If you want to use something other than column B, change the 2 to the right column index
        For i = 2 To lr
            If .Cells(i, 1).MergeCells = True Then
                If .Cells(i, 1).MergeArea.Item(1).Address = .Cells(i, 1).Address Then
                    .Cells(i, 1) = counter
                    counter = counter + 1
                End If
            End If
        Next i
    End With