I would like to join and merge the cells in column B using the "merged rnages" in column A
On top of that the same for column c.
I used the solution from jim may but run into trouble.
[h=2]"
Re: How to Find the Next non-empty cell using vba excel (plus merge it)
[/h]
Any help is welcome
On top of that the same for column c.
I used the solution from jim may but run into trouble.
[h=2]"
[/h]
Sample Table BEFORE Running of Macro (Foo)...
Excel 2010
<colgroup><col style="background-color: #DAE7F5"><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Paste below into a standard Module:
Code:
Sub Foo()
Dim arr()
Dim LR As Long, ct As Long, t As Long
Dim Rng As Range, c As Range
Application.ScreenUpdating = False
LR = Range("B" & Rows.Count).End(xlUp).Row
ct = 1
Set Rng = Range("A2:A" & LR)
For Each c In Rng
If c.Value <> "" Then
ReDim Preserve arr(ct)
arr(ct) = c.Row
ct = ct + 1
End If
Next c
For t = 1 To UBound(arr) - 1
With Range(Cells(arr(t), "A"), Cells(arr(t + 1) - 1, "A"))
.Merge
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
Next t
With Range(Cells(arr(t), "A"), Cells(LR, "A"))
.Merge
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
Application.ScreenUpdating = True
End Sub
Back up your Data before trying this..."
Excel 2010
A | B | C | D | |
---|---|---|---|---|
1 | COL_A_HEADER | B | C | D |
2 | AAA | 121 | 359 | 236 |
3 | 395 | 175 | 255 | |
4 | 198 | 449 | 255 | |
5 | 238 | 133 | 151 | |
6 | 254 | 208 | 109 | |
7 | BBB | 437 | 464 | 349 |
8 | 477 | 436 | 358 | |
9 | 223 | 290 | 383 | |
10 | 178 | 124 | 148 | |
11 | 270 | 335 | 128 | |
12 | CCC | 492 | 249 | 428 |
13 | 170 | 366 | 131 | |
14 | 294 | 470 | 420 | |
15 | 411 | 204 | 261 | |
16 | 368 | 107 | 293 | |
17 | DDD | 208 | 300 | 353 |
18 | 129 | 445 | 289 | |
19 | 354 | 185 | 292 | |
20 | 365 | 430 | 455 |
<colgroup><col style="background-color: #DAE7F5"><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1
Paste below into a standard Module:
Code:
Sub Foo()
Dim arr()
Dim LR As Long, ct As Long, t As Long
Dim Rng As Range, c As Range
Application.ScreenUpdating = False
LR = Range("B" & Rows.Count).End(xlUp).Row
ct = 1
Set Rng = Range("A2:A" & LR)
For Each c In Rng
If c.Value <> "" Then
ReDim Preserve arr(ct)
arr(ct) = c.Row
ct = ct + 1
End If
Next c
For t = 1 To UBound(arr) - 1
With Range(Cells(arr(t), "A"), Cells(arr(t + 1) - 1, "A"))
.Merge
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
Next t
With Range(Cells(arr(t), "A"), Cells(LR, "A"))
.Merge
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
Application.ScreenUpdating = True
End Sub
Back up your Data before trying this..."
Any help is welcome