Hello ,
Add a new VBA Module to your workbook. Copy and paste the macro code below into it.
Sub AddBorders()
With Sheets("Shop Order")
' The following code works with page 2 of the shop order worksheet specifically with System B.
' In this first if statement, it is assumed that system B will not be in use at all.
If .Range("A73") = "" Then
.Range("C71:N74").Borders.LineStyle = 0 'this comment clears out all boxes for system B
End If
' the following code creates one thick outline box because this carriage will have only one section.
If .Range("A73") <> "" And Range("I46") >= 1 Then
.Range("E72:N74").Borders.LineStyle = 0 ' This line clears out all boxes for system B after the first carriage box
With .Range("C72:D74") ' This line draws in 1 thick border box spanning two columns and three rows.
' Remove all diagonal borders
.Borders(5).LineStyle = xlNone
.Borders(6).LineStyle = xlNone
.Borders(11).LineStyle = xlNone
.Borders(12).LineStyle = xlNone
' Add borders around each cell
For i = 7 To 10
With .Borders(i)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
Next i
End With
End If
End Sub
The Worksheet_Change event code will then be like this...
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$E$31" Then
call AddBorders 'and this macro will actually be the code that you see creating the boxes with borders behind sheet2 ("Shop Orders")
End If
End Sub
Bookmarks