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

killpaddy

Board Regular
Joined
Jul 31, 2012
Messages
52
Hi,

I have a afew columns of data related to eachother. Column A contains text in some cells then afew blank cells then another cell with text etc.
I would like to merge the text cells with all the blank cells below it (until the next non-empty cell is reached).
However, I dont know the code to 'find next non-empty cell'
Here's my code so far:
Code:
Dim startfrom As Long
Dim Merge1 As Long
Dim Merge2 As Long

startfrom = 1
Do
    Merge1 = Range("A" & startfrom & ":A" & LastRow).Find("").Row - 1
    Merge2 = Range("A" & Merge1 & ":A" & LastRow).Find([!""]).Row  'error here
    Range("A" & Merge1 & ":A" & Merge2 - 1).Merge
    startfrom = Merge2

Loop Until Range("A" & LastRow) Is Not Nothing 'error probably here aswell

Ive tried different combinations of the '[!""]' and none of them work. can anyone suggest code that would work?

Also how to you get it to 'merge and centre'?

And does anyone know if I save this workbook as a .CSV file whether it will still contain the merged cells when opened somewhere else?

Any help would be appreciated, Thanks
 
Following the exapmle above
"Sample Table BEFORE Running of Macro (Foo)..."

What could i do to join and merge the cell values in column B and column C with the the range from column A
 
Last edited:
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Forum statistics

Threads
1,223,770
Messages
6,174,437
Members
452,564
Latest member
crangelag

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