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
1COL_A_HEADERBCD
2AAA121359236
3395175255
4198449255
5238133151
6254208109
7BBB437464349
8477436358
9223290383
10178124148
11270335128
12CCC492249428
13170366131
14294470420
15411204261
16368107293
17DDD208300353
18129445289
19354185292
20365430455

<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
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,215,430
Messages
6,124,849
Members
449,194
Latest member
HellScout

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