VBA - How to Clear ONLY bottom border of Rows in a range?

HDEmpsall

New Member
Joined
May 3, 2018
Messages
7
I can set a border with:

Dim rnge3 as Range
Dim rowstart as Integer, rowend as Integer

set rnge3 = Worksheets(3).Range("A" & rowstart & ":AU" & rowend)
With rnge3.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = 3
End With

But when I want to clear that border, using .LineStyle = .xlLineStyleNone fails, as does .xlNone.

I do NOT want to clear vertical borders, NOR ANY borders from the top (heading) rows of the sheet.
Many of my attempts fail to compile. The attempts that compile fail to work!
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
It doesn't really make sense to set weight and colour for no border. Just use:

Code:
set rnge3 = Worksheets(3).Range("A" & rowstart & ":AU" & rowend)
rnge3.Borders(xlEdgeBottom).LineStyle = xlNone
 
Upvote 0
It doesn't really make sense to set weight and colour for no border. Just use:

Code:
set rnge3 = Worksheets(3).Range("A" & rowstart & ":AU" & rowend)
rnge3.Borders(xlEdgeBottom).LineStyle = xlNone


I agree entirely. It compiles but doesn't work. (It is driving me crazy)
 
Upvote 0
It works fine for me. What version of Excel are you using?
 
Upvote 0
Microsoft Office 365
Excel Version 1804 Build 9226.2114 (Click to run)
Up to date (just checked)

OS is Windows 10

I have to confess that I am not very good with VBA. It is possible that I have inadvertently disabled something or turned something off.
The code I wrote in the initial post does indeed set the border where I want it. But it is useless if I cannot clear it before the next run of the subroutine.
 
Upvote 0
Can you put an example file somewhere (Dropbox, OneDrive etc) that I can have a look at just to see if it works for me, or if there's something about the workbook? I won't be able to test with 365 until tomorrow.
 
Upvote 0
Yes, I will try, though these methods of sending files post-date my retirement from the IT world and I do not use them much.
I will try OneDrive now. I created a folder on OneDrive called Excel VBA.
The link is https://1drv.ms/x/s!AuWjZTyqK4w4gbFC-FRzRGNOvaZW3g
The best thing would be to send you the whole .xlsm file. However, it is very large and contains links to other workbooks.
And I have no idea how security will work - it might stop you running it for fear of viruses etc.
I apologise for my ignorance. I am self-taught in VBA, so you will likely disapprove intensely of my code!
There is a small 'clearborder()' subroutine at the very end of the VBA code. It operates on the 3rd worksheet. I want to clear the border in the (early) clear worksheets section of the 'Analyze_Clips' subroutine.
 
Upvote 0
I have now created a really simple small file, "TestBorderVBA.xlsm"
The OneDrive link is
https://1drv.ms/x/s!AuWjZTyqK4w4gbFEy4ntf3LEbSGSpg

It contains 2 subroutines: setborder(), clearborder()
setborder() works every time.
clearborder() will clear borders created manually, but NOT the borders created using setborder()
I have run out of ideas as to what to change next!
 
Upvote 0
I think I may be getting nearer.
Code:
rnge3.Borders(xlInsideHorizontal).LineStyle = Excel.LineStyle.xlLineStyleNone
This works. It is what I need.
I had misunderstood the meaning of xlEdgeBottom. It means only the last row in the range, not the cells inside the range.
Now that I have realized this it seems obvious, but it didn't before.
I think the problem is solved. Thank you for your interest and contribution. I feel a bit guilty that my mistake was so trivial!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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