Merging Cells and Adding Boarders Using VBA

The Noob

New Member
Joined
Apr 2, 2020
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Alright, I just created an account and I am hoping to find some help here. I have worked in excel quite a bit and I am very comfortable with using formulas and such. I have never dug into Macros or VBA due to the fact that I have no coding experience. I have created a sheet where I bring in exported data from another program. My sheet takes that data and organizes it into a material list. I am running into the situation now where I am trying to get the headers of each section to merge and add formatting. I do not think this can be done without a macro. I started digging into it today, and this is what I have so far.

If you look at capture 1, it shows my original list without any macros. I have written a short script to get the cells to merge (see capture 2 for script) (capture 3 for results). I am now trying to apply formatting to those merged cells.
I would like the merged cells to have a thick continuous border, and bold size 14 text.

I am sure this is a cake walk for most of you! I am new to this side of excel and kind of excited to finally start digging into it.
 

Attachments

  • Capture 1.PNG
    Capture 1.PNG
    170.2 KB · Views: 17
  • Capture 2.PNG
    Capture 2.PNG
    52.8 KB · Views: 20
  • Capture 3.PNG
    Capture 3.PNG
    169.8 KB · Views: 19

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
I think the best way is to do a macro recording and then modify the macro generated by Excel.
 
Upvote 0
@The Noob

Great to know you have cracked some of the coding
This code will be a help to you and you can modify as per your wish list. Enjoy

VBA Code:
sub Bodermerge()
Dim c As Range
For Each c In testing 
   If c.MergeCells Then
       With c.MergeArea
            .Interior.ColorIndex = 19
            .Borders.LineStyle = xlContinuous
            .Borders.Weight = xlThick
            .Borders.Color = vbGreen
       End With
   End If
 Next
 End Sub
as per your wish
 
Upvote 0
@vmjan02

Works perfectly, thanks! I have been messing around with VBA for a few days now and I finally seem to be getting a grasp on it! (no longer trying to compile and getting errors over and over again)
Feels good to finally start learning a little coding and macros after putting it off for so long.
 
Upvote 0

Forum statistics

Threads
1,214,951
Messages
6,122,449
Members
449,083
Latest member
Ava19

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