Quantcast
Channel: Quality Center / ALM Practitioners Forum topics
Viewing all articles
Browse latest Browse all 5491

Editing multiple worksheets in post-processing

$
0
0

I am creating a report using multiple worksheets and want to do post-processing upon both sheets.  

 

Breakdown of edititing:

Sheet = Severity

* Bold headings

* Add Total and dynamically sum calculations (at first empty row, for each column)

* Autofit each column

* Add a border around entire results

 

Sheet = Outstanding

* Bold headings

* Autofit each column

* Set Columnt Width for for 2 columns

* Set rowheight for entire sheet

 

 

When I generate the excel workbook it does all the post processing in the "Outstanding" worksheet. 

 

 

Sub QC_PostProcessing()

 Dim MainWorksheet As Worksheet
 Set MainWorksheet = ActiveWorkbook.Worksheets("Severity")
 Dim DataRange As Range
 Set DataRange = MainWorksheet.UsedRange

' Bold Headings
 Range("A1").Select
 ActiveCell.Font.Bold = True
 Range("B1").Select
 ActiveCell.Font.Bold = True
 Range("C1").Select
 ActiveCell.Font.Bold = True
 Range("D1").Select
 ActiveCell.Font.Bold = True
 Range("E1").Select
 ActiveCell.Font.Bold = True
 Range("F1").Select
 ActiveCell.Font.Bold = True
 Range("G1").Select
 ActiveCell.Font.Bold = True

'  Add the word TOTAL
 Range("A1").End(xlDown).Offset(1,0).Select
 ActiveCell.Value = "TOTAL"
 ActiveCell.Font.Bold = True

' Dynamically sum the column 
 Dim Lst As Long
 Dim Rng As Range

 Range("B20").End(xlUp).Select
 Lst = ActiveCell.Row
 Set Rng = Range("B2:B" & Lst)
 ActiveCell.Offset(1, 0).Select
 ActiveCell.Formula = "=SUM(" & RNG.Address & ")"
 ActiveCell.Font.Bold = True

 Range("C20").End(xlUp).Select
 Lst = ActiveCell.Row
 Set Rng = Range("C2:C" & Lst)
 ActiveCell.Offset(1, 0).Select
 ActiveCell.Formula = "=SUM(" & RNG.Address & ")"
 ActiveCell.Font.Bold = True

 Range("D20").End(xlUp).Select
 Lst = ActiveCell.Row
 Set Rng = Range("D2:D" & Lst)
 ActiveCell.Offset(1, 0).Select
 ActiveCell.Formula = "=SUM(" & RNG.Address & ")"
 ActiveCell.Font.Bold = True

 Range("E20").End(xlUp).Select
 Lst = ActiveCell.Row
 Set Rng = Range("E2:E" & Lst)
 ActiveCell.Offset(1, 0).Select
 ActiveCell.Formula = "=SUM(" & RNG.Address & ")"
 ActiveCell.Font.Bold = True

 Range("F20").End(xlUp).Select
 Lst = ActiveCell.Row
 Set Rng = Range("F2:F" & Lst)
 ActiveCell.Offset(1, 0).Select
 ActiveCell.Formula = "=SUM(" & RNG.Address & ")"
 ActiveCell.Font.Bold = True

 Range("G20").End(xlUp).Select
 Lst = ActiveCell.Row
 Set Rng = Range("G2:G" & Lst)
 ActiveCell.Offset(1, 0).Select
 ActiveCell.Formula = "=SUM(" & RNG.Address & ")"
 ActiveCell.Font.Bold = True

' Autofit each column
 Columns("A:A").EntireColumn.AutoFit
 Columns("B:B").EntireColumn.AutoFit
 Columns("C:C").EntireColumn.AutoFit
 Columns("D:D").EntireColumn.AutoFit
 Columns("E:E").EntireColumn.AutoFit
 Columns("F:F").EntireColumn.AutoFit
 Columns("G:G").EntireColumn.AutoFit

' Add a border around entire results 
 Application.ScreenUpdating = False
 Dim lngLstCol As Long, lngLstRow As Long

 lngLstRow = ActiveSheet.UsedRange.Rows.Count
 lngLstCol = ActiveSheet.UsedRange.Columns.Count

 For Each rngCell In Range("A1:A" & lngLstRow)
    If rngCell.Value > "" Then
        r = rngCell.Row
        c = rngCell.Column
        Range(Cells(r, c), Cells(r, lngLstCol)).Select
            With Selection.Borders
                .LineStyle = xlContinuous
                .Weight = xlThin
                .ColorIndex = xlAutomatic
            End With
    End If
 Next

 Application.ScreenUpdating = True



 Dim MainWorksheet1 As Worksheet
 Set MainWorksheet1 = ActiveWorkbook.Worksheets("Outstanding")

 Dim DataRange1 As Range
 Set DataRange1 = MainWorksheet.UsedRange

' Bold headings 
 Range("A1").Select
 ActiveCell.Font.Bold = True
 Range("B1").Select
 ActiveCell.Font.Bold = True
 Range("C1").Select
 ActiveCell.Font.Bold = True
 Range("D1").Select
 ActiveCell.Font.Bold = True
 Range("E1").Select
 ActiveCell.Font.Bold = True
 Range("F1").Select
 ActiveCell.Font.Bold = True
 Range("G1").Select
 ActiveCell.Font.Bold = True
 Range("H1").Select
 ActiveCell.Font.Bold = True
 Range("I1").Select
 ActiveCell.Font.Bold = True

' Autofit each column, Set column height for 2 columns, Set row height for entire worksheet
 Columns("A:A").EntireColumn.AutoFit
 Columns("B:B").EntireColumn.AutoFit
 Columns("C:C").EntireColumn.AutoFit
 Columns("D:D").EntireColumn.AutoFit
 Columns("G:G").EntireColumn.AutoFit
 Columns("H:H").EntireColumn.AutoFit
 Columns("I:I").EntireColumn.AutoFit
 Columns("E:E").ColumnWidth = 45
 Columns("F:F").ColumnWidth = 45
 With ActiveSheet
   .Cells.RowHeight = 15
 End With


End Sub

 

 


Viewing all articles
Browse latest Browse all 5491

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>