I have an excel spreadsheet where I want to merge each cell with a value in it with every empty cell below it until the next cell in that column with a value.
Currently I have this:
Sub mergemainbody()
lrow = ActiveSheet.UsedRange.Rows.Count - 2
On Error Resume Next
Application.DisplayAlerts = False
For col = 1 To 50
For Each ar In Cells(3, col).Resize(lrow).SpecialCells (xlCellTypeBlanks).Areas
ar.Resize(ar.Rows.Count + 1).Offset(-1).Merge
Next
Next
End Sub
Which works on an entire sheet, but I want the macro to only apply to a selected area. However, simply changing For col = 1 to 50
to For Each cell In Selection
makes the macro seemingly do nothing.
Example of data:
Heading | Heading | Heading | Heading |
1456262 | 270520 | 574038 | 583059 |
Words | --------- | --------- | --------- |
586048 | --------- | --------- | --------- |
Words | 694574 | 856738 | 068438 |
Where --- shows the cell is empty.