Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 139
Default More Concise Way To Assign Borders?

As a total noob, working from MS Access VBA,
I find myself doing a lot of this:

-------------------------------------------
2010 With theWS
' ----------------------------------------------
' Place Deal/Tranche name centered at top with
' borders and colored background

2020 With .Range(.Cells(mRowNum_Header1, mColNum_First),
..Cells(mRowNum_Header1, mColNum_Last))
2021 .Merge
2022 .Value = theDealName & "-" & theTrancheNumber
2023 .HorizontalAlignment = xlCenter
2029 .Interior.ColorIndex = gExcelColor_MediumBlue

2040 With .Borders(xlLeft)
2041 .Weight = xlMedium
2042 .LineStyle = xlSolid
2049 End With

2040 With .Borders(xlRight)
2041 .Weight = xlMedium
2042 .LineStyle = xlSolid
2049 End With

2040 With .Borders(xlTop)
2041 .Weight = xlMedium
2042 .LineStyle = xlSolid
2049 End With

2040 With .Borders(xlBottom)
2041 .Weight = xlMedium
2042 .LineStyle = xlSolid
2049 End With

2049 End With
2999 End With
------------------------------------------

I tried .BordersAround, but Excel didn't buy it.

Is there something else?
--
PeteCresswell
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default More Concise Way To Assign Borders?

Pete, A couple of ways:

With Range("A1")
With .Borders
.Weight = xlMedium
End With
End With

Range("D1").BorderAround xlSolid, xlMedium

NickHK

"(PeteCresswell)" wrote in message
...
As a total noob, working from MS Access VBA,
I find myself doing a lot of this:

-------------------------------------------
2010 With theWS
' ----------------------------------------------
' Place Deal/Tranche name centered at top with
' borders and colored background

2020 With .Range(.Cells(mRowNum_Header1, mColNum_First),
.Cells(mRowNum_Header1, mColNum_Last))
2021 .Merge
2022 .Value = theDealName & "-" & theTrancheNumber
2023 .HorizontalAlignment = xlCenter
2029 .Interior.ColorIndex = gExcelColor_MediumBlue

2040 With .Borders(xlLeft)
2041 .Weight = xlMedium
2042 .LineStyle = xlSolid
2049 End With

2040 With .Borders(xlRight)
2041 .Weight = xlMedium
2042 .LineStyle = xlSolid
2049 End With

2040 With .Borders(xlTop)
2041 .Weight = xlMedium
2042 .LineStyle = xlSolid
2049 End With

2040 With .Borders(xlBottom)
2041 .Weight = xlMedium
2042 .LineStyle = xlSolid
2049 End With

2049 End With
2999 End With
------------------------------------------

I tried .BordersAround, but Excel didn't buy it.

Is there something else?
--
PeteCresswell



  #3   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default More Concise Way To Assign Borders?

You could put the border contstants in an array then loop through the array.
The for loop would go inside of your With statement. Example below. Or, you
might write a separate sub and pass arguments to it for LineStyle and Weight
and the border constants (passing an array for the borders since they could
vary or maybe use a parameter array).


Dim arrBorders as variant
Dim i as long

arrBorders = Array(xlLeft, xlRight, xlTop xlBottom)

2010 With theWS
' ----------------------------------------------
' Place Deal/Tranche name centered at top with
' borders and colored background

2020 With .Range(.Cells(mRowNum_Header1, mColNum_First),
..Cells(mRowNum_Header1, mColNum_Last))
2021 .Merge
2022 .Value = theDealName & "-" & theTrancheNumber
2023 .HorizontalAlignment = xlCenter
2029 .Interior.ColorIndex = gExcelColor_MediumBlue

for i = lbound(arrborders) to ubound(arrborders)
With .Borders(arrBorders(i))
.Weight = xlMedium
.LineStyle = xlSolid
End With
next i


2049 End With
2999 End With







"(PeteCresswell)" wrote:

As a total noob, working from MS Access VBA,
I find myself doing a lot of this:

-------------------------------------------
2010 With theWS
' ----------------------------------------------
' Place Deal/Tranche name centered at top with
' borders and colored background

2020 With .Range(.Cells(mRowNum_Header1, mColNum_First),
..Cells(mRowNum_Header1, mColNum_Last))
2021 .Merge
2022 .Value = theDealName & "-" & theTrancheNumber
2023 .HorizontalAlignment = xlCenter
2029 .Interior.ColorIndex = gExcelColor_MediumBlue

2040 With .Borders(xlLeft)
2041 .Weight = xlMedium
2042 .LineStyle = xlSolid
2049 End With

2040 With .Borders(xlRight)
2041 .Weight = xlMedium
2042 .LineStyle = xlSolid
2049 End With

2040 With .Borders(xlTop)
2041 .Weight = xlMedium
2042 .LineStyle = xlSolid
2049 End With

2040 With .Borders(xlBottom)
2041 .Weight = xlMedium
2042 .LineStyle = xlSolid
2049 End With

2049 End With
2999 End With
------------------------------------------

I tried .BordersAround, but Excel didn't buy it.

Is there something else?
--
PeteCresswell

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default More Concise Way To Assign Borders?

I tried .BordersAround, but Excel didn't buy it.

It wouldn't, it's a typo, see below

Sub test()

With ActiveSheet
With .Range(.Cells(3, 2), .Cells(3, 6))
With .Cells(1, 1)
.Value = "my text or value"
.HorizontalAlignment = xlCenter
'gExcelColor_MediumBlue, guessing -
'will match to nearest colour in the palette
.Interior.Color = RGB(153, 204, 255)
' or asumming a default palette
'.Interior.ColorIndex = 37
End With
.Merge
.BorderAround xlSolid, xlMedium
' or if using late binding
'.BorderAround 1, -4138
End With
End With
End Sub

Regards,
Peter T

"(PeteCresswell)" wrote in message
...
As a total noob, working from MS Access VBA,
I find myself doing a lot of this:

-------------------------------------------
2010 With theWS
' ----------------------------------------------
' Place Deal/Tranche name centered at top with
' borders and colored background

2020 With .Range(.Cells(mRowNum_Header1, mColNum_First),
.Cells(mRowNum_Header1, mColNum_Last))
2021 .Merge
2022 .Value = theDealName & "-" & theTrancheNumber
2023 .HorizontalAlignment = xlCenter
2029 .Interior.ColorIndex = gExcelColor_MediumBlue

2040 With .Borders(xlLeft)
2041 .Weight = xlMedium
2042 .LineStyle = xlSolid
2049 End With

2040 With .Borders(xlRight)
2041 .Weight = xlMedium
2042 .LineStyle = xlSolid
2049 End With

2040 With .Borders(xlTop)
2041 .Weight = xlMedium
2042 .LineStyle = xlSolid
2049 End With

2040 With .Borders(xlBottom)
2041 .Weight = xlMedium
2042 .LineStyle = xlSolid
2049 End With

2049 End With
2999 End With
------------------------------------------

I tried .BordersAround, but Excel didn't buy it.

Is there something else?
--
PeteCresswell



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default More Concise Way To Assign Borders?

Just to add, probably better to use constants like xlEdgeLeft rather than
xlLeft.

If looping the outside borders could do it this way

With rng
For i = 7 To 10
.Borders(i).Weight = xlMedium
.Borders(i).LineStyle = xlSolid
Next
End With

To include inside borders, whether or not there are any, simply apply to
..Borders in one go.

..Borders.Weight = xlMedium
..Borders.LineStyle = xlSolid

Regards,
Peter T

"JMB" wrote in message
...
You could put the border contstants in an array then loop through the

array.
The for loop would go inside of your With statement. Example below. Or,

you
might write a separate sub and pass arguments to it for LineStyle and

Weight
and the border constants (passing an array for the borders since they

could
vary or maybe use a parameter array).


Dim arrBorders as variant
Dim i as long

arrBorders = Array(xlLeft, xlRight, xlTop xlBottom)

2010 With theWS
' ----------------------------------------------
' Place Deal/Tranche name centered at top with
' borders and colored background

2020 With .Range(.Cells(mRowNum_Header1, mColNum_First),
..Cells(mRowNum_Header1, mColNum_Last))
2021 .Merge
2022 .Value = theDealName & "-" & theTrancheNumber
2023 .HorizontalAlignment = xlCenter
2029 .Interior.ColorIndex = gExcelColor_MediumBlue

for i = lbound(arrborders) to ubound(arrborders)
With .Borders(arrBorders(i))
.Weight = xlMedium
.LineStyle = xlSolid
End With
next i


2049 End With
2999 End With







"(PeteCresswell)" wrote:

As a total noob, working from MS Access VBA,
I find myself doing a lot of this:

-------------------------------------------
2010 With theWS
' ----------------------------------------------
' Place Deal/Tranche name centered at top with
' borders and colored background

2020 With .Range(.Cells(mRowNum_Header1, mColNum_First),
..Cells(mRowNum_Header1, mColNum_Last))
2021 .Merge
2022 .Value = theDealName & "-" & theTrancheNumber
2023 .HorizontalAlignment = xlCenter
2029 .Interior.ColorIndex = gExcelColor_MediumBlue

2040 With .Borders(xlLeft)
2041 .Weight = xlMedium
2042 .LineStyle = xlSolid
2049 End With

2040 With .Borders(xlRight)
2041 .Weight = xlMedium
2042 .LineStyle = xlSolid
2049 End With

2040 With .Borders(xlTop)
2041 .Weight = xlMedium
2042 .LineStyle = xlSolid
2049 End With

2040 With .Borders(xlBottom)
2041 .Weight = xlMedium
2042 .LineStyle = xlSolid
2049 End With

2049 End With
2999 End With
------------------------------------------

I tried .BordersAround, but Excel didn't buy it.

Is there something else?
--
PeteCresswell



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
Make instructions clear, concise and in plain english. Jo Excel Discussion (Misc queries) 0 May 19th 06 03:31 AM
Concise border removal method XP Excel Programming 1 January 11th 06 08:10 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 11:45 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"