0
votes

For e.g. I have three values (numbers) in cells B1, B2 and B3. These explain how many cells I should merge in column A. For example B1 = 6, B2 =3 and B3 = 2 then I want to merge cell range A16 to A22 (16+6), then A23 to A26 should be a new merged range and the last merged range should be A27 to A29.

1

1 Answers

1
votes

Could you show the code that you have already written?

I think you have to use the function Merge in your range.

The code below works great for me :

Sub merge()
    Dim i As Integer
    Dim i2 As Integer
    Dim i3 As Integer
    i = Range("B1")
    i2 = Range("B2")
    i3 = Range("B3")
    Range("A1:A" & i).merge
    Range("A" & (i + 1) & ":A" & (i + i2)).merge
    Range("A" & (i + i2 + 1) & ":A" & (i + i2 + i3)).merge
End Sub