Using LastRow and Borders

Offroadracer_814

New Member
Joined
Aug 7, 2015
Messages
24
First off, thanks for the help.

I am using LastRow to find the last row of data in my spreadsheet. The last row in my spreadsheet varies daily.

Dim LastRow As Long
Range("A1").Select
LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

Then I am trying use the thin border on the bottom of the cells.
Range("A3").Select
Range("A3:AF" & LastRow).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With

However, the last row is not getting a border. Can someone help?

Thanks

Kevin
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
It borders to the last row for me with values.
What do you have in the cells on the last row values, formulas or just formats?
 
Upvote 0
Do the 2 message boxes below give the same and correct number?

Code:
Sub xxx2()
    Dim LastRow As Long, LastRow2 As Long

    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    MsgBox LastRow
    LastRow2 = ActiveSheet.Cells.SpecialCells(11).Row
    MsgBox LastRow2
End Sub

and is the correct sheet Active?
 
Last edited:
Upvote 0
Do the 2 message boxes below give the same and correct number?

Code:
Sub xxx2()
    Dim LastRow As Long, LastRow2 As Long

    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    MsgBox LastRow
    LastRow2 = ActiveSheet.Cells.SpecialCells(11).Row
    MsgBox LastRow2
End Sub

and is the correct sheet Active?

Yes to all questions.
 
Upvote 0
Afraid then I have no suggestions (other than adding a +1 to the LastRow code) without seeing the workbook.
If you can upload the workbook to either www.box.com or www.dropbox.com I'll take a look (make sure any sensitive data is sanitised).

Mark the file for sharing and paste the link it provides in the thread.
 
Last edited:
Upvote 0
Afraid then I have no suggestions (other than adding a +1 to the LastRow code) without seeing the workbook.
If you can upload the workbook to either www.box.com or www.dropbox.com I'll take a look (make sure any sensitive data is sanitised).

Mark the file for sharing and paste the link it provides in the thread.

Will do... firewall will not allow me to dropbox. I will try it from home.
Along with a fee for box.com. I will not be using that option.

Thanks
 
Upvote 0
The fee on box is only for businesses, it is free for personal use else I wouldn't use it. Click Individual.
 
Last edited:
Upvote 0
So you do not have to put anytime into it at all.
I did have to because it was bugging me :biggrin: but the code underlined from row 3 to row 58 for me which looks correct, do you get a different result?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,169
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