Macro to edit borders in top and bottom rows in a selection

Darrell MacDonald

New Member
Joined
Mar 25, 2021
Messages
14
Office Version
  1. 2010
Platform
  1. Windows
Hello
I'm hoping to have code suggestions that will find the top row of a selection, make the borders medium, then find the bottom row of the same selection and do the same.

Many thanks for any suggestions.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Is this what you mean?

VBA Code:
Sub MediumBorders()
  With Selection
    .Rows(1).BorderAround xlContinuous, xlMedium
    .Rows(.Rows.Count).BorderAround xlContinuous, xlMedium
  End With
End Sub
 
Upvote 0
Thanks very much for responding so quickly, Peter

I'll try to describe it better. Here's what I'm hoping to do. Take a non-formatted selection, as per the first image I attached and format its borders as per the second image. The selection of cells will change every time. Thick outline overall, hairline inside where the numbers are, bold font and thin line at the bottom of the top row (where the titles are) and bold font with a thin border on its top for just the bottom row (where the sums are). So, there are actually 3 selections to format within the total selection set (top line, bottom line and middle section).

Many years ago, someone had given me code that did all of this in one macro but I've lost that, and some other similar ones.
 

Attachments

  • Blank selection.jpg
    Blank selection.jpg
    21.5 KB · Views: 3
  • Desired Result.jpg
    Desired Result.jpg
    33.3 KB · Views: 3
Upvote 0
How about
VBA Code:
Sub Darrell()
   With Selection
      .Borders.Weight = xlHairline
      .BorderAround xlContinuous, xlMedium
      With .Rows(1)
         .Font.Bold = True
         .Borders(xlBottom).Weight = xlThin
      End With
      With .Rows(.Rows.Count)
         .Font.Bold = True
         .Borders(xlTop).Weight = xlThin
      End With
   End With
End Sub
 
Upvote 0
Solution
Glad we could help & thanks for the feedback.
 
Upvote 0
I'm now able to take that code and copy/modify it to suit other similar, repetitive tasks. I add the new macros to customized ribbon sections for such things. Very, very useful for the specific things I do over and over. Thanks again. You folks rock. I'm always amazed by the willingness of people on boards like this to help.
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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