VBA code for borders -

cagni

New Member
Joined
Aug 1, 2022
Messages
24
Office Version
  1. 365
Platform
  1. Windows
Hi

I hope someone can help me with vba code for borders in my sheet.

I have a Commandbutton which creates a new line, where it changes the the borders to xlThin. This is fine for the bottom line, but I would like to have top and both sides thicker like the ones above. I just don´t know how to do this.

I know the code I have made could probably also be made alot simpler.

Let me know if it doesnt make sense.

VBA Code:
Private Sub CommandButton1_Click()

Dim iRow As Long

ActiveSheet.Range("A7").Select
ActiveCell.EntireRow.Insert shift:=xlDown

ActiveSheet.Range("A7").Select
ActiveCell.EntireRow.RowHeight = 15

ActiveSheet.Range("B7:U7").Select
Selection.Interior.ColorIndex = 0

ActiveSheet.Range("B7:U7").Select
Selection.Borders.Weight = xlThin

ActiveSheet.Range("B7:U7").Select
Selection.Font.Size = 11

ActiveSheet.Range("K7").Select
Selection.Interior.ColorIndex = 48

ActiveSheet.Range("L7").Select
Selection.Interior.ColorIndex = 44

ActiveSheet.Range("B7:U8").Select
Selection.Font.Bold = False


End Sub

2023-05-25 14_20_55-Window.jpg
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
So what exactly is the issue?
Does your current code need to be generalized, or does it not quite do what you need?
If you Turn on the Macro Recorder, and record yourself performing the actions you want manually, then stop the Macro Recorder, you will have the base code that does most of what you need.
We can then help you generalize it, if you need (i.e. make it work dynamically on the current row instead of just on row 7).
 
Upvote 0
So what exactly is the issue?
Does your current code need to be generalized, or does it not quite do what you need?
If you Turn on the Macro Recorder, and record yourself performing the actions you want manually, then stop the Macro Recorder, you will have the base code that does most of what you need.
We can then help you generalize it, if you need (i.e. make it work dynamically on the current row instead of just on row 7).
Thanks

Often forget this options is there. Recorded what I needed and now it works.
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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