Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 23
Default help needed with borders

Hello. I am hoping someone can help me with this little problem. I have this bit of code that tidies up my spreadsheet for me. It makes all the font the same, autofits the columns and then adds borders around all the data. It seems to work ok unless theres only one row of data under my headings "(which are in rows 1, 2 and 3). If there's only one row of data then the code puts borders right the way doing the entire spreadsheet. it should only go around the rows with data.

'\\ Select everything
Cells.Select

'\\ Autofit
' Cells.EntireColumn.AutoFit

'\\ Set Font and Style
With Selection.Font
.Name = "Arial"
.Size = 11
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With

'\\ Cell Alignment
Columns("A:F").Select
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom

End With

'\\ Add borders to info below header rows
Range("A4").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With


thank you.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default help needed with borders

Hi,

Am Mon, 26 Nov 2012 17:53:45 +0000 schrieb kardifflad:

Hello. I am hoping someone can help me with this little problem. I have
this bit of code that tidies up my spreadsheet for me. It makes all the
font the same, autofits the columns and then adds borders around all the
data. It seems to work ok unless theres only one row of data under my
headings "(which are in rows 1, 2 and 3). If there's only one row of
data then the code puts borders right the way doing the entire
spreadsheet. it should only go around the rows with data.


try:

Sub Test()
Dim LRow As Long
Dim myRange As Range
Dim BorderRange As Range

LRow = Cells(Rows.Count, 1).End(xlUp).Row
Set myRange = Range("A1:F" & LRow)
Set BorderRange = Range("A4:F" & LRow)

With myRange
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom

With .Font
.Name = "Arial"
.Size = 11
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
End With

With BorderRange
With .Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With

With .Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With

With .Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With

With .Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With

With .Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With

With .Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End With

End Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #3   Report Post  
Junior Member
 
Posts: 23
Default

that worked absolutely perfectly. thank you very much for your kind assistance. Much appreciated.
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 mhenley5 Excel Discussion (Misc queries) 2 May 5th 09 11:09 PM
BORDERS [email protected] Excel Programming 1 February 13th 07 03:01 AM
Borders anita Excel Worksheet Functions 6 September 15th 06 01:15 PM
borders Brush Prairie Excel Discussion (Misc queries) 0 August 23rd 05 02:57 AM
Borders Alan Excel Programming 3 November 10th 04 06:40 PM


All times are GMT +1. The time now is 01:15 PM.

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

About Us

"It's about Microsoft Excel"