Merge Cells

ng6971

New Member
Joined
Apr 18, 2011
Messages
35
Hi everyone,

I have a spreadsheet contains multiple column data on it. In column B there are some bold character entries.
Condition is that wherever bold entries in column B, if there are blank cells between column C to column J,
merge all the cells between Column B to Column J in whole spreadsheet by a vba code.

Thanks in advance.
 

Attachments

  • Image.jpg
    Image.jpg
    142.8 KB · Views: 8

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Here you go
VBA Code:
Private Sub ng6971_ConditionalMerging()
    Dim ws As Worksheet: Set ws = Sheets("Sheet1") ' Change sheet name if required
    Dim lr As Long, rw As Long, col As Long
    
    lr = ws.Cells(Rows.Count, 2).End(3).Row
    For rw = 2 To lr
        If ws.Cells(rw, 2).Font.Bold Then
            For col = 3 To 10
                If ws.Cells(rw, col).Value = "" Then
                    ws.Cells(rw, 3).Resize(, 8).Merge
                End If
            Next col
        End If
    Next rw
End Sub
 
Upvote 0
Solution
Here you go
VBA Code:
Private Sub ng6971_ConditionalMerging()
    Dim ws As Worksheet: Set ws = Sheets("Sheet1") ' Change sheet name if required
    Dim lr As Long, rw As Long, col As Long
   
    lr = ws.Cells(Rows.Count, 2).End(3).Row
    For rw = 2 To lr
        If ws.Cells(rw, 2).Font.Bold Then
            For col = 3 To 10
                If ws.Cells(rw, col).Value = "" Then
                    ws.Cells(rw, 3).Resize(, 8).Merge
                End If
            Next col
        End If
    Next rw
End Sub
Sir, thank you so much for solution. Regards.
 
Upvote 0
Thanks for your feedback, I feel like I should tell you that even if it finds 1 empty cell between columns C and J .. it will merge, if you would like me to change that, let me know, if it's not an issue then nevermind :)
 
Upvote 0

Forum statistics

Threads
1,214,942
Messages
6,122,366
Members
449,080
Latest member
Armadillos

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