Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Borders - non-contiguous ranges

Hello,

The following macro places borders around the range
A6:D50:

Sub myborders()
Dim ws As Worksheet
Dim Lastrow As Integer

Set ws = Sheets(1)
Lastrow = 50

With ws.Range("A6:D" & Lastrow)
With .Borders
.LineStyle = xlBorderLineStyleContinuous
.Weight = xlThin
End With
End With

End Sub

However, the project has several non-contiguous ranges
that require formatting with borders. I wish to achieve
this without repeating for each range, the code starting
with "With ws.range("A6:D" & Lastrow)".

This is the type of thing that I am looking for (this
syntax does not work):
With ws.range("A6:D" & Lastrow, "K6:L" & Lastrow, "P6:S"
& LastRow)

I will appreciate any suggestions on the above matter.

TIA

Richard

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Borders - non-contiguous ranges

With ws.range("A6:D" & Lastrow & ",K6:L" & Lastrow & ",P6:S"
& LastRow)

--
Regards,
Tom Ogilvy



"Richard" wrote in message
...
Hello,

The following macro places borders around the range
A6:D50:

Sub myborders()
Dim ws As Worksheet
Dim Lastrow As Integer

Set ws = Sheets(1)
Lastrow = 50

With ws.Range("A6:D" & Lastrow)
With .Borders
.LineStyle = xlBorderLineStyleContinuous
.Weight = xlThin
End With
End With

End Sub

However, the project has several non-contiguous ranges
that require formatting with borders. I wish to achieve
this without repeating for each range, the code starting
with "With ws.range("A6:D" & Lastrow)".

This is the type of thing that I am looking for (this
syntax does not work):
With ws.range("A6:D" & Lastrow, "K6:L" & Lastrow, "P6:S"
& LastRow)

I will appreciate any suggestions on the above matter.

TIA

Richard



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Borders - non-contiguous ranges

Thank Tom, works perfectly. I tried something like that
but obviously had the apostrophes in the wrong place.
I've just replace about 50 lines of code with 6.

Regards,

Richard

-----Original Message-----
With ws.range("A6:D" & Lastrow & ",K6:L" & Lastrow

& ",P6:S"
& LastRow)

--
Regards,
Tom Ogilvy



"Richard" wrote in

message
...
Hello,

The following macro places borders around the range
A6:D50:

Sub myborders()
Dim ws As Worksheet
Dim Lastrow As Integer

Set ws = Sheets(1)
Lastrow = 50

With ws.Range("A6:D" & Lastrow)
With .Borders
.LineStyle = xlBorderLineStyleContinuous
.Weight = xlThin
End With
End With

End Sub

However, the project has several non-contiguous ranges
that require formatting with borders. I wish to achieve
this without repeating for each range, the code

starting
with "With ws.range("A6:D" & Lastrow)".

This is the type of thing that I am looking for (this
syntax does not work):
With ws.range("A6:D" & Lastrow, "K6:L" &

Lastrow, "P6:S"
& LastRow)

I will appreciate any suggestions on the above matter.

TIA

Richard



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Borders - non-contiguous ranges

Tom,

If i wnanted to just put outside boarders (and leave
inside as it is)for non-contiguous ranges , what code
would I need? Thanks.

-----Original Message-----
With ws.range("A6:D" & Lastrow & ",K6:L" & Lastrow

& ",P6:S"
& LastRow)

--
Regards,
Tom Ogilvy



"Richard" wrote in

message
...
Hello,

The following macro places borders around the range
A6:D50:

Sub myborders()
Dim ws As Worksheet
Dim Lastrow As Integer

Set ws = Sheets(1)
Lastrow = 50

With ws.Range("A6:D" & Lastrow)
With .Borders
.LineStyle = xlBorderLineStyleContinuous
.Weight = xlThin
End With
End With

End Sub

However, the project has several non-contiguous ranges
that require formatting with borders. I wish to achieve
this without repeating for each range, the code starting
with "With ws.range("A6:D" & Lastrow)".

This is the type of thing that I am looking for (this
syntax does not work):
With ws.range("A6:D" & Lastrow, "K6:L" & Lastrow, "P6:S"
& LastRow)

I will appreciate any suggestions on the above matter.

TIA

Richard



.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Borders - non-contiguous ranges

Jamal,

Using Tom's code snippet, this will place a border around
A6:D50, K6:L50, P6:S50. Change to suit. See the VBA Help
file for the BorderAround method, in particular, the
properties to change the line style, line weight and
color.

Sub myBordersAround()
Dim lastrow As Integer
Dim ws As Worksheet
Dim rng As Range

lastrow = 50
Set ws = Sheets(1)
Set rng = ws.Range("A6:D" & lastrow & ",K6:L" & lastrow
& ",P6:S" & lastrow)

' Clear existing borders
' Cells.Borders.LineStyle = xlLineStyleNone

're-establish borders
'rng.BorderAround , , ColorIndex:=xlColorIndexAutomatic
rng.BorderAround LineStyle:=xlContinuous,
Weight:=xlThick, _
ColorIndex:=xlColorIndexAutomatic

End Sub

Regards,
Richard

-----Original Message-----
Tom,

If i wnanted to just put outside boarders (and leave
inside as it is)for non-contiguous ranges , what code
would I need? Thanks.

-----Original Message-----
With ws.range("A6:D" & Lastrow & ",K6:L" & Lastrow

& ",P6:S"
& LastRow)

--
Regards,
Tom Ogilvy



"Richard" wrote

in
message
...
Hello,

The following macro places borders around the range
A6:D50:

Sub myborders()
Dim ws As Worksheet
Dim Lastrow As Integer

Set ws = Sheets(1)
Lastrow = 50

With ws.Range("A6:D" & Lastrow)
With .Borders
.LineStyle = xlBorderLineStyleContinuous
.Weight = xlThin
End With
End With

End Sub

However, the project has several non-contiguous ranges
that require formatting with borders. I wish to

achieve
this without repeating for each range, the code

starting
with "With ws.range("A6:D" & Lastrow)".

This is the type of thing that I am looking for (this
syntax does not work):
With ws.range("A6:D" & Lastrow, "K6:L" &

Lastrow, "P6:S"
& LastRow)

I will appreciate any suggestions on the above matter.

TIA

Richard



.

.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Borders - non-contiguous ranges

Richard,
This is very helpful. It changed lot of lines od codes to
a few. Thanks.

-----Original Message-----
Jamal,

Using Tom's code snippet, this will place a border around
A6:D50, K6:L50, P6:S50. Change to suit. See the VBA Help
file for the BorderAround method, in particular, the
properties to change the line style, line weight and
color.

Sub myBordersAround()
Dim lastrow As Integer
Dim ws As Worksheet
Dim rng As Range

lastrow = 50
Set ws = Sheets(1)
Set rng = ws.Range("A6:D" & lastrow & ",K6:L" & lastrow
& ",P6:S" & lastrow)

' Clear existing borders
' Cells.Borders.LineStyle = xlLineStyleNone

're-establish borders
'rng.BorderAround , , ColorIndex:=xlColorIndexAutomatic
rng.BorderAround LineStyle:=xlContinuous,
Weight:=xlThick, _
ColorIndex:=xlColorIndexAutomatic

End Sub

Regards,
Richard

-----Original Message-----
Tom,

If i wnanted to just put outside boarders (and leave
inside as it is)for non-contiguous ranges , what code
would I need? Thanks.

-----Original Message-----
With ws.range("A6:D" & Lastrow & ",K6:L" & Lastrow

& ",P6:S"
& LastRow)

--
Regards,
Tom Ogilvy



"Richard" wrote

in
message
.. .
Hello,

The following macro places borders around the range
A6:D50:

Sub myborders()
Dim ws As Worksheet
Dim Lastrow As Integer

Set ws = Sheets(1)
Lastrow = 50

With ws.Range("A6:D" & Lastrow)
With .Borders
.LineStyle = xlBorderLineStyleContinuous
.Weight = xlThin
End With
End With

End Sub

However, the project has several non-contiguous ranges
that require formatting with borders. I wish to

achieve
this without repeating for each range, the code

starting
with "With ws.range("A6:D" & Lastrow)".

This is the type of thing that I am looking for (this
syntax does not work):
With ws.range("A6:D" & Lastrow, "K6:L" &

Lastrow, "P6:S"
& LastRow)

I will appreciate any suggestions on the above matter.

TIA

Richard



.

.

.

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
Indirect Function Doesn't like non-contiguous ranges Excel Discussion (Misc queries) 7 December 3rd 10 09:59 AM
vlookup on non-contiguous ranges BorisS Excel Worksheet Functions 2 June 15th 06 10:28 AM
summing non contiguous ranges valaor Excel Discussion (Misc queries) 6 March 22nd 06 04:17 PM
Adding Non-Contiguous Ranges COE Excel Discussion (Misc queries) 11 January 24th 06 11:43 PM
sorting non contiguous ranges gsh20 Excel Discussion (Misc queries) 1 September 8th 05 04:50 PM


All times are GMT +1. The time now is 10:29 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"