#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Borders

Hi everyone,

I was wondering if anyone can help me with some code to dynamically place a
border on the last row of a spreadsheet. The issue for me is that the
spreadsheet varies in length (based on filtering), but the columns are static
(A:S). What I was hoping to do is place a border on the last row so the
spreadsheet will be completly framed out once printed.

Does anyone have any ideas?

Thanks,

SJ


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Borders

If all the columns are the same length as Column A then

Sub brdrArnd()
lr = Cells(Rows.Count, 1).End(xlUp).Row
ActiveSheet.Range("A1:S" & lr).BorderAround Weight:=xlMedium
End Sub

However, If you save the file with the border, then when you run the
macro again, if the column length has changed, you will have another
frame for each change in length. You will have to remove the border
before saving to prevent this anomaly.


"Scott J" wrote:

Hi everyone,

I was wondering if anyone can help me with some code to dynamically place a
border on the last row of a spreadsheet. The issue for me is that the
spreadsheet varies in length (based on filtering), but the columns are static
(A:S). What I was hoping to do is place a border on the last row so the
spreadsheet will be completly framed out once printed.

Does anyone have any ideas?

Thanks,

SJ


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Borders


What you could do is put the following line of code after your print
activity is completed.

ActiveSheet.Range("A1:S" & lr).Borders.LineStyle = xlLineStyleNone

That will remove the border so you can do other things and then save the file.
If you plan on the column lengths changing and the file being printed during
a single session, then I suggest you put the border commands in separate subs
and use a conditional If ... Then statement to call them as needed. The
border will not automatically move with a change in the size of the database,
but the macro will resize the border each time it is run, based on the size
of the database. Now that I have you thoroughly confused, I'll say good
night.

"Scott J" wrote:

Hi everyone,

I was wondering if anyone can help me with some code to dynamically place a
border on the last row of a spreadsheet. The issue for me is that the
spreadsheet varies in length (based on filtering), but the columns are static
(A:S). What I was hoping to do is place a border on the last row so the
spreadsheet will be completly framed out once printed.

Does anyone have any ideas?

Thanks,

SJ


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Borders

The problem with this (no time to work it out now), is how you'd want the previous border dealt with. Maybe assign the range to a range name?

Sub BorderLastRow()
'get rid of the previous border?
ActiveSheet.UsedRange.BorderAround LineStyle = xlLineStyleNone
Dim Rw As Long, bRng As Range
Rw = Cells(Rows.Count, 1).End(xlUp).Row
Set bRng = Range("A1:S" & Rw)
bRng.BorderAround Weight:=xlMedium
End Sub


Regards
Robert McCurdy
"Scott J" wrote in message ...
Hi everyone,

I was wondering if anyone can help me with some code to dynamically place a
border on the last row of a spreadsheet. The issue for me is that the
spreadsheet varies in length (based on filtering), but the columns are static
(A:S). What I was hoping to do is place a border on the last row so the
spreadsheet will be completly framed out once printed.

Does anyone have any ideas?

Thanks,

SJ


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Borders

Thanks for the response. This code works well!! I realized after I posted
that I forgot to mention that I would like to have each page have a border
around the entire spreadsheet. So when you print, or hit print preview, no
matter how many rows there are, a border is placed around the entire
spreadseet at every page break.

I hope this makes sense.

Thanks

"JLGWhiz" wrote:


What you could do is put the following line of code after your print
activity is completed.

ActiveSheet.Range("A1:S" & lr).Borders.LineStyle = xlLineStyleNone

That will remove the border so you can do other things and then save the file.
If you plan on the column lengths changing and the file being printed during
a single session, then I suggest you put the border commands in separate subs
and use a conditional If ... Then statement to call them as needed. The
border will not automatically move with a change in the size of the database,
but the macro will resize the border each time it is run, based on the size
of the database. Now that I have you thoroughly confused, I'll say good
night.

"Scott J" wrote:

Hi everyone,

I was wondering if anyone can help me with some code to dynamically place a
border on the last row of a spreadsheet. The issue for me is that the
spreadsheet varies in length (based on filtering), but the columns are static
(A:S). What I was hoping to do is place a border on the last row so the
spreadsheet will be completly framed out once printed.

Does anyone have any ideas?

Thanks,

SJ




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Borders

Robert,

Thanks for your reply. This code works great, and you are correct about
having to turn it off when done printing. Actually, after I posted I
realized I didn't mention that I would really like to have a border around
the entire worksheet at each page break. So, when you print the sheet, the
data on each page has a border around it. The issue is with the last page,
since the amount of data that shows up on that page will vary, so the border
would have to vary.

So, how do I get a macro to place full border around each full page of data
and then a varying page of data?

Thanks again!!

Scott J

"Robert McCurdy" wrote:

The problem with this (no time to work it out now), is how you'd want the previous border dealt with. Maybe assign the range to a range name?

Sub BorderLastRow()
'get rid of the previous border?
ActiveSheet.UsedRange.BorderAround LineStyle = xlLineStyleNone
Dim Rw As Long, bRng As Range
Rw = Cells(Rows.Count, 1).End(xlUp).Row
Set bRng = Range("A1:S" & Rw)
bRng.BorderAround Weight:=xlMedium
End Sub


Regards
Robert McCurdy
"Scott J" wrote in message ...
Hi everyone,

I was wondering if anyone can help me with some code to dynamically place a
border on the last row of a spreadsheet. The issue for me is that the
spreadsheet varies in length (based on filtering), but the columns are static
(A:S). What I was hoping to do is place a border on the last row so the
spreadsheet will be completly framed out once printed.

Does anyone have any ideas?

Thanks,

SJ



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Borders

I think the only way to do that is to print with gridlines visible. You can
set that option in PageSetup.

"Scott J" wrote:

Robert,

Thanks for your reply. This code works great, and you are correct about
having to turn it off when done printing. Actually, after I posted I
realized I didn't mention that I would really like to have a border around
the entire worksheet at each page break. So, when you print the sheet, the
data on each page has a border around it. The issue is with the last page,
since the amount of data that shows up on that page will vary, so the border
would have to vary.

So, how do I get a macro to place full border around each full page of data
and then a varying page of data?

Thanks again!!

Scott J

"Robert McCurdy" wrote:

The problem with this (no time to work it out now), is how you'd want the previous border dealt with. Maybe assign the range to a range name?

Sub BorderLastRow()
'get rid of the previous border?
ActiveSheet.UsedRange.BorderAround LineStyle = xlLineStyleNone
Dim Rw As Long, bRng As Range
Rw = Cells(Rows.Count, 1).End(xlUp).Row
Set bRng = Range("A1:S" & Rw)
bRng.BorderAround Weight:=xlMedium
End Sub


Regards
Robert McCurdy
"Scott J" wrote in message ...
Hi everyone,

I was wondering if anyone can help me with some code to dynamically place a
border on the last row of a spreadsheet. The issue for me is that the
spreadsheet varies in length (based on filtering), but the columns are static
(A:S). What I was hoping to do is place a border on the last row so the
spreadsheet will be completly framed out once printed.

Does anyone have any ideas?

Thanks,

SJ



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Borders

I was affraid that might be the answer. I just wasn't sure if there was some
kind of pagebreak command or something like that to utilize.

"JLGWhiz" wrote:

I think the only way to do that is to print with gridlines visible. You can
set that option in PageSetup.

"Scott J" wrote:

Robert,

Thanks for your reply. This code works great, and you are correct about
having to turn it off when done printing. Actually, after I posted I
realized I didn't mention that I would really like to have a border around
the entire worksheet at each page break. So, when you print the sheet, the
data on each page has a border around it. The issue is with the last page,
since the amount of data that shows up on that page will vary, so the border
would have to vary.

So, how do I get a macro to place full border around each full page of data
and then a varying page of data?

Thanks again!!

Scott J

"Robert McCurdy" wrote:

The problem with this (no time to work it out now), is how you'd want the previous border dealt with. Maybe assign the range to a range name?

Sub BorderLastRow()
'get rid of the previous border?
ActiveSheet.UsedRange.BorderAround LineStyle = xlLineStyleNone
Dim Rw As Long, bRng As Range
Rw = Cells(Rows.Count, 1).End(xlUp).Row
Set bRng = Range("A1:S" & Rw)
bRng.BorderAround Weight:=xlMedium
End Sub


Regards
Robert McCurdy
"Scott J" wrote in message ...
Hi everyone,

I was wondering if anyone can help me with some code to dynamically place a
border on the last row of a spreadsheet. The issue for me is that the
spreadsheet varies in length (based on filtering), but the columns are static
(A:S). What I was hoping to do is place a border on the last row so the
spreadsheet will be completly framed out once printed.

Does anyone have any ideas?

Thanks,

SJ



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Borders Larry L Excel Discussion (Misc queries) 2 August 11th 09 05:45 PM
borders kim Excel Discussion (Misc queries) 1 October 12th 07 10:24 PM
Borders DAH Mist Excel Discussion (Misc queries) 0 October 1st 07 10:24 PM
Borders Alan Excel Programming 3 November 10th 04 06:40 PM
Help with borders Ed[_10_] Excel Programming 0 July 23rd 03 08:07 PM


All times are GMT +1. The time now is 06:40 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"