Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 71
Default Micro to do borders question.

I have a Micro that makes borders for certain range.
I would like to make this code better, because if you add extra row or
delete a row this micro will not do its job right.

The borders will always start at B31, but it can end anywhere. In B30 there
always will be the word "Area" and after the last cell to do borders it will
always be the word "Comments/Issues:".

so can it be done with a "if" statement if the see those words or is there
an other better way?

This is the code.
Sub FixBorders()


ActiveSheet.Unprotect Password:="eli"
Range("B31:O98").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlDouble
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlDouble
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = xlAutomatic
End With
With ActiveSheet
.Protect Password:="eli"
.EnableSelection = xlUnlockedCells
End With
End Sub

Thank you.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,346
Default Micro to do borders question.

Hi,

Why not range name the last cell Last - select it and choose Insert, Name,
Define and enter Last in the Names in Workbook box and then click OK.

In your code replace

Range("B31:O98").Select

with

Range("B31", [Last]).Select

--
If this helps, please click the Yes button.

Cheers,
Shane Devenshire


"Damian" wrote:

I have a Micro that makes borders for certain range.
I would like to make this code better, because if you add extra row or
delete a row this micro will not do its job right.

The borders will always start at B31, but it can end anywhere. In B30 there
always will be the word "Area" and after the last cell to do borders it will
always be the word "Comments/Issues:".

so can it be done with a "if" statement if the see those words or is there
an other better way?

This is the code.
Sub FixBorders()


ActiveSheet.Unprotect Password:="eli"
Range("B31:O98").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlDouble
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlDouble
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = xlAutomatic
End With
With ActiveSheet
.Protect Password:="eli"
.EnableSelection = xlUnlockedCells
End With
End Sub

Thank you.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,346
Default Micro to do borders question.

Here are some additional changes you might consider:

Sub FixBorders()
With Range("B31", [Last])
With .Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
End With
With .Borders(xlEdgeTop)
.LineStyle = xlDouble
.Weight = xlThick
End With
With .Borders(xlEdgeBottom)
.LineStyle = xlDouble
.Weight = xlThick
End With
With .Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
End With
With .Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With .Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlHairline
End With
End With
End Sub

To use this you would protect the spreadsheet but turn on the Format Cells
option in the protection dialog box. That way there is no need to hard code
the password into the code.

--
If this helps, please click the Yes button.

Cheers,
Shane Devenshire


"Damian" wrote:

I have a Micro that makes borders for certain range.
I would like to make this code better, because if you add extra row or
delete a row this micro will not do its job right.

The borders will always start at B31, but it can end anywhere. In B30 there
always will be the word "Area" and after the last cell to do borders it will
always be the word "Comments/Issues:".

so can it be done with a "if" statement if the see those words or is there
an other better way?

This is the code.
Sub FixBorders()


ActiveSheet.Unprotect Password:="eli"
Range("B31:O98").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlDouble
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlDouble
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = xlAutomatic
End With
With ActiveSheet
.Protect Password:="eli"
.EnableSelection = xlUnlockedCells
End With
End Sub

Thank you.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 71
Default Micro to do borders question.

Great, Thank You.
One more thing,

Is there a way to have the the [Last] cell (B99:O99) BUT have the code to do
its job 1 cell up in B98:O98?
I tried to use the .End(xlDown)
but did not work.

Thanks

"Shane Devenshire" wrote:

Here are some additional changes you might consider:

Sub FixBorders()
With Range("B31", [Last])
With .Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
End With
With .Borders(xlEdgeTop)
.LineStyle = xlDouble
.Weight = xlThick
End With
With .Borders(xlEdgeBottom)
.LineStyle = xlDouble
.Weight = xlThick
End With
With .Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
End With
With .Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With .Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlHairline
End With
End With
End Sub

To use this you would protect the spreadsheet but turn on the Format Cells
option in the protection dialog box. That way there is no need to hard code
the password into the code.

--
If this helps, please click the Yes button.

Cheers,
Shane Devenshire


"Damian" wrote:

I have a Micro that makes borders for certain range.
I would like to make this code better, because if you add extra row or
delete a row this micro will not do its job right.

The borders will always start at B31, but it can end anywhere. In B30 there
always will be the word "Area" and after the last cell to do borders it will
always be the word "Comments/Issues:".

so can it be done with a "if" statement if the see those words or is there
an other better way?

This is the code.
Sub FixBorders()


ActiveSheet.Unprotect Password:="eli"
Range("B31:O98").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlDouble
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlDouble
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = xlAutomatic
End With
With ActiveSheet
.Protect Password:="eli"
.EnableSelection = xlUnlockedCells
End With
End Sub

Thank you.

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
Micro Ganesh Kumar Excel Worksheet Functions 2 July 21st 09 04:54 PM
Question about borders Paul Allor Excel Discussion (Misc queries) 3 September 14th 07 04:16 PM
Question about Cell Borders Kevin New Users to Excel 2 April 13th 05 02:36 AM
Micro djmimi Excel Worksheet Functions 0 February 9th 05 06:29 PM
what does the micro do Ibrahim New Users to Excel 1 December 8th 04 02:54 PM


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