Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Exclude sheets from code

I have a bit of code thats automatically sets borders for new sheets.

When the code runs, it changes the borders on all sheets in the workbook. I
would like to have two sheets excluded from this code.

The sheet names are "All" and "Tally"

Here is my code:

Sub Set_Borders()
Dim sht As Worksheet
For Each sht In ActiveWorkbook.Sheets
With sht.Range("A1:An53")
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders.LineStyle = xlContinuous
.Borders.Weight = xlMedium
.Borders.ColorIndex = xlAutomatic
.Borders(xlInsideVertical).Weight = xlHairline
.Borders(xlInsideHorizontal).Weight = xlHairline
End With
With sht.Range("A1:An1")
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders.LineStyle = xlContinuous
.Borders.Weight = xlMedium
.Borders.ColorIndex = xlAutomatic
.Borders(xlEdgeBottom).Weight = xlThin
.Borders(xlInsideVertical).Weight = xlHairline
.Borders(xlInsideHorizontal).Weight = xlHairline
End With
Next sht
Sheets("All").Activate
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Exclude sheets from code

You can use if then but I prefer select case for tis kind of thing...

Sub Set_Borders()
Dim sht As Worksheet
For Each sht In ActiveWorkbook.Sheets
select case sht.name
case "All", "Tally"
case else
With sht.Range("A1:An53")
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders.LineStyle = xlContinuous
.Borders.Weight = xlMedium
.Borders.ColorIndex = xlAutomatic
.Borders(xlInsideVertical).Weight = xlHairline
.Borders(xlInsideHorizontal).Weight = xlHairline
End With
With sht.Range("A1:An1")
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders.LineStyle = xlContinuous
.Borders.Weight = xlMedium
.Borders.ColorIndex = xlAutomatic
.Borders(xlEdgeBottom).Weight = xlThin
.Borders(xlInsideVertical).Weight = xlHairline
.Borders(xlInsideHorizontal).Weight = xlHairline
End With
end select
Next sht
Sheets("All").Activate
End Sub

--
HTH...

Jim Thomlinson


"Homer" wrote:

I have a bit of code thats automatically sets borders for new sheets.

When the code runs, it changes the borders on all sheets in the workbook. I
would like to have two sheets excluded from this code.

The sheet names are "All" and "Tally"

Here is my code:

Sub Set_Borders()
Dim sht As Worksheet
For Each sht In ActiveWorkbook.Sheets
With sht.Range("A1:An53")
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders.LineStyle = xlContinuous
.Borders.Weight = xlMedium
.Borders.ColorIndex = xlAutomatic
.Borders(xlInsideVertical).Weight = xlHairline
.Borders(xlInsideHorizontal).Weight = xlHairline
End With
With sht.Range("A1:An1")
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders.LineStyle = xlContinuous
.Borders.Weight = xlMedium
.Borders.ColorIndex = xlAutomatic
.Borders(xlEdgeBottom).Weight = xlThin
.Borders(xlInsideVertical).Weight = xlHairline
.Borders(xlInsideHorizontal).Weight = xlHairline
End With
Next sht
Sheets("All").Activate
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default Exclude sheets from code

try this:

Option Explicit

Sub Set_Borders()

Dim sht As Worksheet

For Each sht In ActiveWorkbook.Sheets
If sht.Name = "All" Or sht.Name = "Tally" Then
'do nothing
Else
With sht.Range("A1:An53")
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders.LineStyle = xlContinuous
.Borders.Weight = xlMedium
.Borders.ColorIndex = xlAutomatic
.Borders(xlInsideVertical).Weight = xlHairline
.Borders(xlInsideHorizontal).Weight = xlHairline
End With

With sht.Range("A1:An1")
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders.LineStyle = xlContinuous
.Borders.Weight = xlMedium
.Borders.ColorIndex = xlAutomatic
.Borders(xlEdgeBottom).Weight = xlThin
.Borders(xlInsideVertical).Weight = xlHairline
.Borders(xlInsideHorizontal).Weight = xlHairline
End With
End If
Next sht
Sheets("All").Activate
End Sub

worked for me.
:)
susan





On Aug 7, 12:13*pm, Homer wrote:
I have a bit of code thats automatically sets borders for new sheets. *

When the code runs, it changes the borders on all sheets in the workbook. *I
would like to have two sheets excluded from this code. *

The sheet names are "All" and "Tally"

Here is my code:

Sub Set_Borders()
* * Dim sht As Worksheet
* * For Each sht In ActiveWorkbook.Sheets
* * * * With sht.Range("A1:An53")
* * * * .Borders(xlDiagonalDown).LineStyle = xlNone
* * * * .Borders(xlDiagonalUp).LineStyle = xlNone
* * * * .Borders.LineStyle = xlContinuous
* * * * .Borders.Weight = xlMedium
* * * * .Borders.ColorIndex = xlAutomatic
* * * * .Borders(xlInsideVertical).Weight = xlHairline
* * * * .Borders(xlInsideHorizontal).Weight = xlHairline
* * * * End With
* * * * With sht.Range("A1:An1")
* * * * .Borders(xlDiagonalDown).LineStyle = xlNone
* * * * .Borders(xlDiagonalUp).LineStyle = xlNone
* * * * .Borders.LineStyle = xlContinuous
* * * * .Borders.Weight = xlMedium
* * * * .Borders.ColorIndex = xlAutomatic
* * * * .Borders(xlEdgeBottom).Weight = xlThin
* * * * .Borders(xlInsideVertical).Weight = xlHairline
* * * * .Borders(xlInsideHorizontal).Weight = xlHairline
* * * * End With
* * * * Next sht
* * Sheets("All").Activate
End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Exclude sheets from code

Thanks Jim. Code now works as needed.

Don

"Jim Thomlinson" wrote:

You can use if then but I prefer select case for tis kind of thing...

Sub Set_Borders()
Dim sht As Worksheet
For Each sht In ActiveWorkbook.Sheets
select case sht.name
case "All", "Tally"
case else
With sht.Range("A1:An53")
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders.LineStyle = xlContinuous
.Borders.Weight = xlMedium
.Borders.ColorIndex = xlAutomatic
.Borders(xlInsideVertical).Weight = xlHairline
.Borders(xlInsideHorizontal).Weight = xlHairline
End With
With sht.Range("A1:An1")
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders.LineStyle = xlContinuous
.Borders.Weight = xlMedium
.Borders.ColorIndex = xlAutomatic
.Borders(xlEdgeBottom).Weight = xlThin
.Borders(xlInsideVertical).Weight = xlHairline
.Borders(xlInsideHorizontal).Weight = xlHairline
End With
end select
Next sht
Sheets("All").Activate
End Sub

--
HTH...

Jim Thomlinson


"Homer" wrote:

I have a bit of code thats automatically sets borders for new sheets.

When the code runs, it changes the borders on all sheets in the workbook. I
would like to have two sheets excluded from this code.

The sheet names are "All" and "Tally"

Here is my code:

Sub Set_Borders()
Dim sht As Worksheet
For Each sht In ActiveWorkbook.Sheets
With sht.Range("A1:An53")
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders.LineStyle = xlContinuous
.Borders.Weight = xlMedium
.Borders.ColorIndex = xlAutomatic
.Borders(xlInsideVertical).Weight = xlHairline
.Borders(xlInsideHorizontal).Weight = xlHairline
End With
With sht.Range("A1:An1")
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders.LineStyle = xlContinuous
.Borders.Weight = xlMedium
.Borders.ColorIndex = xlAutomatic
.Borders(xlEdgeBottom).Weight = xlThin
.Borders(xlInsideVertical).Weight = xlHairline
.Borders(xlInsideHorizontal).Weight = xlHairline
End With
Next sht
Sheets("All").Activate
End Sub

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
Exclude hidden sheets from formatting Bart[_8_] Excel Programming 2 September 29th 08 05:32 PM
Exclude HTML code Marie Bayes Excel Discussion (Misc queries) 0 May 21st 08 03:45 PM
Step through sheets, but exclude one CLR Excel Programming 3 October 19th 07 08:19 PM
Exclude Sheets from Macro Lambtwo Excel Programming 6 August 17th 06 10:22 PM
Edit code - exclude sheets Steph[_6_] Excel Programming 7 March 15th 06 03:35 PM


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

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

About Us

"It's about Microsoft Excel"