Code Skipping Over Code and Going to End of Program

Guzzlr

Well-known Member
Joined
Apr 20, 2009
Messages
982
Office Version
  1. 2021
Platform
  1. Windows
VBA Code:
For Each sht In ActiveWorkbook.Worksheets
    If sht.Visible And sht.Name = "NCR" And sht.Name = "Planned" Then
    sht.Activate


'Justify each Worksheet
With ActiveSheet
Cells.Select
With Selection
  .HorizontalAlignment = xlCenter
  .VerticalAlignment = xlCenter
  .WrapText = True
  .Orientation = 0
  .AddIndent = False
  .IndentLevel = 0
  .ShrinkToFit = False
  .ReadingOrder = xlContext
  .MergeCells = False
  .RowHeight = 200
    Rows("1:1").RowHeight = 32
    Columns("B:B").ColumnWidth = 8.14
    Columns("C:C").ColumnWidth = 20
    Columns("D:D").ColumnWidth = 20
    Columns("E:E").ColumnWidth = 62
    Columns("F:F").ColumnWidth = 62
    Columns("G:G").ColumnWidth = 62
'     Rows("1:1").Select
'    Selection.RowHeight = 32
   

End With

'Draw Border
Range("A1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
   

   
   
'Delete all Unused Columns to End
Range("H:H", Cells(1, Columns.Count).End(xlToLeft).EntireColumn).Delete

End With
End If
Next sht

Hello All,
My code above is not working to justify or draw boarders. Basically, for the worksheets of NCR and Planned, I want to justify and draw boarders, then delete all columns from HH:HH to end.
However, My loop is skipping the two worksheets of NCR and Planned, and going right to the end.
How can I get the code to find the two sheets of NCR and Planned, then preform the proper formatting?
Thanks for the help
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Assuming that both sheets are visible use If sht.Name = "NCR" Or sht.Name = "Planned" Then
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top