How to Find the Next non-empty cell using vba excel (plus merge it) one step further

ACRAENS

New Member
Joined
Mar 25, 2010
Messages
3
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]"
icon1.png
Re: How to Find the Next non-empty cell using vba excel (plus merge it)
[/h]
Sample Table BEFORE Running of Macro (Foo)...

Excel 2010
ABCD
COL_A_HEADERBCD
AAA
BBB
CCC
DDD

<colgroup><col style="background-color: #DAE7F5"><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"] 1 [/TD]

[TD="align: center"] 2 [/TD]

[TD="align: right"] 121 [/TD]
[TD="align: right"] 359 [/TD]
[TD="align: right"] 236 [/TD]

[TD="align: center"] 3 [/TD]
[TD="align: right"][/TD]
[TD="align: right"] 395 [/TD]
[TD="align: right"] 175 [/TD]
[TD="align: right"] 255 [/TD]

[TD="align: center"] 4 [/TD]
[TD="align: right"][/TD]
[TD="align: right"] 198 [/TD]
[TD="align: right"] 449 [/TD]
[TD="align: right"] 255 [/TD]

[TD="align: center"] 5 [/TD]
[TD="align: right"][/TD]
[TD="align: right"] 238 [/TD]
[TD="align: right"] 133 [/TD]
[TD="align: right"] 151 [/TD]

[TD="align: center"] 6 [/TD]
[TD="align: right"][/TD]
[TD="align: right"] 254 [/TD]
[TD="align: right"] 208 [/TD]
[TD="align: right"] 109 [/TD]

[TD="align: center"] 7 [/TD]

[TD="align: right"] 437 [/TD]
[TD="align: right"] 464 [/TD]
[TD="align: right"] 349 [/TD]

[TD="align: center"] 8 [/TD]
[TD="align: right"][/TD]
[TD="align: right"] 477 [/TD]
[TD="align: right"] 436 [/TD]
[TD="align: right"] 358 [/TD]

[TD="align: center"] 9 [/TD]
[TD="align: right"][/TD]
[TD="align: right"] 223 [/TD]
[TD="align: right"] 290 [/TD]
[TD="align: right"] 383 [/TD]

[TD="align: center"] 10 [/TD]
[TD="align: right"][/TD]
[TD="align: right"] 178 [/TD]
[TD="align: right"] 124 [/TD]
[TD="align: right"] 148 [/TD]

[TD="align: center"] 11 [/TD]
[TD="align: right"][/TD]
[TD="align: right"] 270 [/TD]
[TD="align: right"] 335 [/TD]
[TD="align: right"] 128 [/TD]

[TD="align: center"] 12 [/TD]

[TD="align: right"] 492 [/TD]
[TD="align: right"] 249 [/TD]
[TD="align: right"] 428 [/TD]

[TD="align: center"] 13 [/TD]
[TD="align: right"][/TD]
[TD="align: right"] 170 [/TD]
[TD="align: right"] 366 [/TD]
[TD="align: right"] 131 [/TD]

[TD="align: center"] 14 [/TD]
[TD="align: right"][/TD]
[TD="align: right"] 294 [/TD]
[TD="align: right"] 470 [/TD]
[TD="align: right"] 420 [/TD]

[TD="align: center"] 15 [/TD]
[TD="align: right"][/TD]
[TD="align: right"] 411 [/TD]
[TD="align: right"] 204 [/TD]
[TD="align: right"] 261 [/TD]

[TD="align: center"] 16 [/TD]
[TD="align: right"][/TD]
[TD="align: right"] 368 [/TD]
[TD="align: right"] 107 [/TD]
[TD="align: right"] 293 [/TD]

[TD="align: center"] 17 [/TD]

[TD="align: right"] 208 [/TD]
[TD="align: right"] 300 [/TD]
[TD="align: right"] 353 [/TD]

[TD="align: center"] 18 [/TD]
[TD="align: right"][/TD]
[TD="align: right"] 129 [/TD]
[TD="align: right"] 445 [/TD]
[TD="align: right"] 289 [/TD]

[TD="align: center"] 19 [/TD]
[TD="align: right"][/TD]
[TD="align: right"] 354 [/TD]
[TD="align: right"] 185 [/TD]
[TD="align: right"] 292 [/TD]

[TD="align: center"] 20 [/TD]
[TD="align: right"][/TD]
[TD="align: right"] 365 [/TD]
[TD="align: right"] 430 [/TD]
[TD="align: right"] 455 [/TD]

</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
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top