Hi,
I've a macro which formats a sheet
Model1 -
Group1 Group2 Group3
Model Act Var Model Act Var Model Act Var
Model 2
Group1 Group2 Group3
Model Act Var Model Act Var Model Act Var
Model 3
Group1 Group2 Group3
Model Act Var Model Act Var Model Act Var
Model in Group1 is always ColumnD
Act in Group1 is always ColumnE
Var l in Group1 is always ColumnF
Model in Group2 is always ColumnH
Act in Group2 is always ColumnI
Var l in Group2 is always ColumnJ
Model in Group3 is always ColumnL
Act in Group3 is always ColumnM
Var l in Group3 is always ColumnN
I need to put borders around each of the three groups
for example
Range("D8:F10").Select
Selection.Borders(xlDiagon
alDown).Li
neStyle = xlNone
Selection.Borders(xlDiagon
alUp).Line
Style = xlNone
With Selection.Borders(xlEdgeLe
ft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 1
End With
With Selection.Borders(xlEdgeTo
p)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 1
End With
With Selection.Borders(xlEdgeBo
ttom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 1
End With
With Selection.Borders(xlEdgeRi
ght)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 1
End With
Currently the code is
Sub Csformatting_6()
'Dim wks As Worksheet
'For Each wks In ActiveWorkbook.Worksheets
'Dim wks As Worksheet
'For Each wks In ActiveWorkbook.Worksheets
'wks.Select
Cells.Select
Selection.Sort Key1:=Range("G2"), Order1:=xlDescending, Key2:=Range("C2") _
, Order2:=xlAscending, header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Selection.Insert Shift:=xlDown
Selection.Insert Shift:=xlDown
Range("A9").Select
Cells.Select
Range("A:Z").Activate
Selection.Borders(xlDiagon
alDown).Li
neStyle = xlNone
Selection.Borders(xlDiagon
alUp).Line
Style = xlNone
With Selection.Borders(xlEdgeLe
ft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 15
End With
With Selection.Borders(xlEdgeTo
p)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 15
End With
With Selection.Borders(xlEdgeBo
ttom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 15
End With
With Selection.Borders(xlEdgeRi
ght)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 15
End With
With Selection.Borders(xlInside
Vertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 15
End With
With Selection.Borders(xlInside
Horizontal
)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 15
End With
Call Model_b
Call Model_c
Call Model_d
For lRow = 2 To Cells.SpecialCells(xlCellT
ypeLastCel
l).row
If Cells(lRow, 1).Value <> " " Then
Range("K" & lRow).NumberFormat = "0%"
Range("L" & lRow).NumberFormat = "0%"
Range("O" & lRow).NumberFormat = "0%"
Range("P" & lRow).NumberFormat = "0%"
Range("S" & lRow).NumberFormat = "0%"
Range("T" & lRow).NumberFormat = "0%"
Range("W" & lRow).NumberFormat = "0%"
Range("X" & lRow).NumberFormat = "0%"
End If
Next lRow
Columns("C:H").Select
Range("H1").Activate
Selection.Delete Shift:=xlToLeft
Columns("G:G").Select
Selection.Delete Shift:=xlToLeft
Columns("J:J").Select
Selection.Delete Shift:=xlToLeft
Columns("M:M").Select
Selection.Delete Shift:=xlToLeft
Columns("P:P").Select
Selection.Delete Shift:=xlToLeft
Columns("C:C").Select
Selection.Delete Shift:=xlToLeft
Rows("4:4").Select
Selection.Delete Shift:=xlUp
Columns("A:A").ColumnWidth
= 17.14
'
ActiveWindow.Zoom = 75
Range("A4").Select
ActiveCell.Value = "Discretionary Accounts"
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.MergeCells = False
.Font.Size = 12
.Font.ColorIndex = 1
End With
Columns("F:F").Select
Selection.Insert Shift:=xlToRight
Columns("J:J").Select
Selection.Insert Shift:=xlToRight
Columns("N:N").Select
Selection.Insert Shift:=xlToRight
Range("A1").Select
Columns("A:A").ColumnWidth
= 14
Columns("B:B").ColumnWidth
= 36
Columns("D:D").ColumnWidth
= 7.57
Columns("E:E").ColumnWidth
= 9.43
Columns("F:F").ColumnWidth
= 7.29
Columns("H:H").ColumnWidth
= 8.86
Columns("I:I").ColumnWidth
= 10.29
Columns("M:M").ColumnWidth
= 8.57
Columns("L:L").ColumnWidth
= 7.14
Columns("N:N").ColumnWidth
= 7.86
Columns("O:O").ColumnWidth
= 6.14
Columns("P:P").ColumnWidth
= 8.14
Columns("Q:Q").ColumnWidth
= 8.43
Rows("4:4").Select
Selection.Delete Shift:=xlUp
Rows("4:4").Select
Selection.Delete Shift:=xlUp
End If
Columns("C:C").Select
Selection.Insert Shift:=xlToRight
Range("C6").Select
Columns("C:C").ColumnWidth
= 2.86
'Next
End Sub
''''''''''''''''''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''''''''''
''
Sub Model_b()
col = 3 'your column number
startRow = 1 ' Row where the data starts
col_header = 1
col7 = 7
RowsA = Cells(Rows.Count, col).End(xlUp).row
For i = startRow To RowsA
If Cells(i, col) = "B" And Cells(i, col7) = "D" Then
For j = 1 To 5
Rows(i).EntireRow.Insert
Next j
Cells(i + 2, col_header).Value = "Model 1"
With Cells(i + 2, col_header)
' .Value = "Model 1"
.Font.Bold = True
.Font.ColorIndex = 1
.HorizontalAlignment = xlLeft
End With
Cells(i + 3, col_header + 10).Value = "Group1"
With Cells(i + 3, col_header + 10)
.HorizontalAlignment = xlCenter
.Font.Bold = True
.Font.ColorIndex = 1
End With
Cells(i + 4, col7 + 3).Value = "Model"
With Cells(i + 4, col7 + 3)
.Font.Bold = True
.Font.ColorIndex = 1
End With
Cells(i + 4, col7 + 4).Value = "Act"
With Cells(i + 4, col7 + 4)
.Font.Bold = True
.Font.ColorIndex = 1
End With
Cells(i + 4, col7 + 5).Value = "Var"
With Cells(i + 4, col7 + 5)
.Font.Bold = True
.Font.ColorIndex = 1
End With
Cells(i + 3, col_header + 14).Value = "Group2"
With Cells(i + 3, col_header + 14)
.Font.Bold = True
.Font.ColorIndex = 1
End With
Cells(i + 4, col7 + 7).Value = "Model"
With Cells(i + 4, col7 + 7)
.Font.Bold = True
.Font.ColorIndex = 1
End With
Cells(i + 4, col7 + 8).Value = "Act"
With Cells(i + 4, col7 + 8)
.Font.Bold = True
.Font.ColorIndex = 1
End With
Cells(i + 4, col7 + 9).Value = "Var"
With Cells(i + 4, col7 + 9)
.Font.Bold = True
.Font.ColorIndex = 1
End With
Cells(i + 3, col_header + 18).Value = "Group3"
With Cells(i + 3, col_header + 18)
.Font.Bold = True
.Font.ColorIndex = 1
End With
Cells(i + 4, col7 + 11).Value = "Model"
With Cells(i + 4, col7 + 11)
.Font.Bold = True
.Font.ColorIndex = 1
End With
Cells(i + 4, col7 + 12).Value = "Act"
With Cells(i + 4, col7 + 12)
.Font.Bold = True
.Font.ColorIndex = 1
End With
Cells(i + 4, col7 + 13).Value = "Var"
With Cells(i + 4, col7 + 13)
.Font.Bold = True
.Font.ColorIndex = 1
End With
Range("A" & i + 4, "Y" & i + 4).Select
With Selection.Borders(xlEdgeBo
ttom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = 1
End With
Application.ScreenUpdating
= True
Application.Calculation = xlCalculationAutomatic
Exit Sub
End If
Next i
End Sub
--------------------------
----------
----------
----------
----------
----------
----------
----------
----------
---------
The problem is that the borders are dependent on how much data is in Model.