Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default Do I need these lines?

Greetings all. I recorded some putting a bold line around a range, and I am
using it for around 20 or so ranges in a macro. The recorded lines are
below...


With CurrentRange
' .Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeLeft).Weight = xlMedium
' .Borders(xlEdgeLeft).ColorIndex = xlAutomatic
' .Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeTop).Weight = xlMedium
' .Borders(xlEdgeTop).ColorIndex = xlAutomatic
' .Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeBottom).Weight = xlMedium
' .Borders(xlEdgeBottom).ColorIndex = xlAutomatic
' .Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeRight).Weight = xlMedium
' .Borders(xlEdgeRight).ColorIndex = xlAutomatic
End With

My question is, with this having to be in my macro so many times, I am
trying to shrink it down some. I commented out all but the .weight lines,
and for all appearances, the borders look the same with or without the
commented out lines running. I am using XL 2007. What could potentially go
wrong if I do not include them in the macro? Thank you.

Greg
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Do I need these lines?

Hi Greg,

No you do not need the superfluous lines. As a little added information you
can set a range to a union of multiple ranges like the following and add the
borders to each of the ranges in the union.

Note that a space and underscore at the end of a line is a line break in an
otherwise single line of code.


Dim currentRange As Range

Set currentRange = Union(Range("B2:D5"), _
Range("B11:D15"), _
Range("B21:D25"))

With currentRange
.Borders(xlEdgeLeft).Weight = xlMedium
.Borders(xlEdgeTop).Weight = xlMedium
.Borders(xlEdgeBottom).Weight = xlMedium
.Borders(xlEdgeRight).Weight = xlMedium
End With

--
Regards,

OssieMac


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default Do I need these lines?

hi
all of the lines in your code are setting the parameters of A cell (range).
IF the parameters of the cell (range) are ALREADY set to the parameters, then
you don't need to include these lines. why set something that is already set?
you need only to include the lines that accually change something...cell or
range.
vague advice maybe but...in a way....very to the point.
why set something that is already set?????? why have code to change
something if nothing is being changed????

regards
FSt1

"Greg Snidow" wrote:

Greetings all. I recorded some putting a bold line around a range, and I am
using it for around 20 or so ranges in a macro. The recorded lines are
below...


With CurrentRange
' .Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeLeft).Weight = xlMedium
' .Borders(xlEdgeLeft).ColorIndex = xlAutomatic
' .Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeTop).Weight = xlMedium
' .Borders(xlEdgeTop).ColorIndex = xlAutomatic
' .Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeBottom).Weight = xlMedium
' .Borders(xlEdgeBottom).ColorIndex = xlAutomatic
' .Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeRight).Weight = xlMedium
' .Borders(xlEdgeRight).ColorIndex = xlAutomatic
End With

My question is, with this having to be in my macro so many times, I am
trying to shrink it down some. I commented out all but the .weight lines,
and for all appearances, the borders look the same with or without the
commented out lines running. I am using XL 2007. What could potentially go
wrong if I do not include them in the macro? Thank you.

Greg

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default Do I need these lines?

I had no idea about joining ranges like that, thanks for the tip. I've never
seen that.

Greg

"OssieMac" wrote:

Hi Greg,

No you do not need the superfluous lines. As a little added information you
can set a range to a union of multiple ranges like the following and add the
borders to each of the ranges in the union.

Note that a space and underscore at the end of a line is a line break in an
otherwise single line of code.


Dim currentRange As Range

Set currentRange = Union(Range("B2:D5"), _
Range("B11:D15"), _
Range("B21:D25"))

With currentRange
.Borders(xlEdgeLeft).Weight = xlMedium
.Borders(xlEdgeTop).Weight = xlMedium
.Borders(xlEdgeBottom).Weight = xlMedium
.Borders(xlEdgeRight).Weight = xlMedium
End With

--
Regards,

OssieMac


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default Do I need these lines?

As an extra line-saver:

set CurrentRange = Union(...)
currentrange.borderaround weight:=xlmedium

Sam

"Greg Snidow" wrote:

I had no idea about joining ranges like that, thanks for the tip. I've never
seen that.

Greg

"OssieMac" wrote:

Hi Greg,

No you do not need the superfluous lines. As a little added information you
can set a range to a union of multiple ranges like the following and add the
borders to each of the ranges in the union.

Note that a space and underscore at the end of a line is a line break in an
otherwise single line of code.


Dim currentRange As Range

Set currentRange = Union(Range("B2:D5"), _
Range("B11:D15"), _
Range("B21:D25"))

With currentRange
.Borders(xlEdgeLeft).Weight = xlMedium
.Borders(xlEdgeTop).Weight = xlMedium
.Borders(xlEdgeBottom).Weight = xlMedium
.Borders(xlEdgeRight).Weight = xlMedium
End With

--
Regards,

OssieMac


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
In Excel 2007 chart with multiple lines, mouse doesn't track lines sfuelling Charts and Charting in Excel 1 August 19th 09 09:41 PM
inserted lines move how to place lines in proper cell? Deschi Excel Worksheet Functions 0 February 8th 09 01:15 PM
Sub to copy only result lines within formula range, omit null string lines Max Excel Programming 2 July 15th 07 04:21 AM
Inserting Lines or Copying lines with formulas but without data wnfisba Excel Discussion (Misc queries) 2 August 18th 06 04:41 PM
excel97 vba to append lines to text file overwriting last 2 lines Paul Excel Programming 1 November 6th 04 08:11 PM


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