Merging cells and thicker border VBA Code

johnydoo

New Member
Joined
Apr 13, 2016
Messages
3
I am trying to merge cells an add a thicker border based on values in a list. The values in the list start at 1 and go to a maximum of 10; however, the list can stop at any number before 10 and restart to 1. I have the current code inputted in my properties:

Code:
Sub merge()
Dim srw As Long, frw As Variant
With Worksheets("Sheet1")
    With Intersect(.Columns(3), .UsedRange)
        srw = 7
        Do While srw < .Rows.Count
            frw = Application.Match(1, .Columns(1).Offset(srw + 1, 0), 0)
            If Not IsError(frw) Then
                .Cells(srw + 1, 1).Resize(frw, 1).Offset(0, -1).merge
                srw = srw + frw
            Else
                srw = .Cells(Rows.Count, 1).End(xlUp).Row
            End If
        Loop
    End With
End With
End Sub

This code produces the following image:

http://i.stack.imgur.com/SiZkD.jpg

I was wondering what I could add/edit the code to not depend on that extra "1" to merge the cells in Column B. Also, I was wondering what code I could add to make the borders thicker above the "1" or below the last number (similar situation to the previous sentence - so when I am at the end of the list, I don't need to add an extra "1" to use the thicker border). I have attached an example of how I picture it looking.

http://i.stack.imgur.com/ZYWfe.jpg

I am in Excel 2013. I am fairly inexperienced with VBA code so any help is appreciated. If more information is needed, let me know. Thank you.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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