?
Solved

Format Excel sheet with last row having sum and percentage formulas in the columns

Posted on 2010-11-11
7
Medium Priority
?
585 Views
Last Modified: 2012-06-27
This is the second part of the orginial question titled:   Format Excel sheet with a row suming the columns

The solution provided did what I asked, sum the columns on the last row.  But I forgot that 4 columns required a different formula and format (percentages).  The percentage columns (F:I) use this formula accordingly: =IF(C8=0,0,C8/B8)

Need help updating the code to incorporate the percentage formula into the last row and also format it as a percentage (100.00%).

Thanks in advance.


Sub PostProcessing()
Dim MainWorksheet As Worksheet
' Make sure your worksheet name matches!
Set MainWorksheet = ActiveWorkbook.Worksheets("Have")
Dim DataRange As Range
Dim lastRow As Long
Set DataRange = MainWorksheet.UsedRange
' Now that you have the data in DataRange you can process it.

    mainworksheet.range("A1:J1").Font.Bold = True
    mainworksheet.range("A1:J1").Interior.ColorIndex = 15


With MainWorksheet
    .Rows(1).Insert

    With .Rows(2)
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With

    With .Range("B1:J1")
        .Merge
        .HorizontalAlignment = xlCenter
        .Font.Bold = True
        .FormulaR1C1 = "Test Execution Sprint View"
        .Font.Name = "Arial"
        .Font.Size = 12
    End With

    .[a2] = "Cycles"

    lastRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1

    .Cells(lastRow, 1) = "Release Grand Total"
    .Cells(lastRow, 2).Resize(1, 9).FormulaR1C1 = "=sum(R3C:R[-1]C)"

    With .Cells(lastRow, 1).Resize(1, 10).Interior
        .Pattern = xlSolid
        .ColorIndex = 37
    End With

End With



End Sub

Open in new window

Execution-20Status-20by-20Sprint.xls
0
Comment
Question by:j420exe1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 8

Expert Comment

by:Kelvin81
ID: 34112548
Sorry,

I'd like to help but am a bit confused.  I can't find your other questions for some reason (Haven't used EE in a while most likely).

Could you tell me:
" The percentage columns (F:I) use this formula accordingly: =IF(C8=0,0,C8/B8)"  What cell is that going in?  

If you put that into the last row (assuming 8 in this case) of column F you want it to give you C/B?  

0
 
LVL 8

Expert Comment

by:Kelvin81
ID: 34112563
DOH just saw attachment, disregard please.
0
 
LVL 8

Expert Comment

by:Kelvin81
ID: 34113272
I believe this will do what you want.

Regards,
Kelvin





Sub PostProcessing()
Dim MainWorksheet As Worksheet
' Make sure your worksheet name matches!
Set MainWorksheet = ActiveWorkbook.Worksheets("Have")
Dim DataRange As Range
Dim lastRow As Long
Set DataRange = MainWorksheet.UsedRange
' Now that you have the data in DataRange you can process it.

    MainWorksheet.Range("A1:J1").Font.Bold = True
    MainWorksheet.Range("A1:J1").Interior.ColorIndex = 15


With MainWorksheet
    .Rows(1).Insert

    With .Rows(2)
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With

    With .Range("B1:J1")
        .Merge
        .HorizontalAlignment = xlCenter
        .Font.Bold = True
        .FormulaR1C1 = "Test Execution Sprint View"
        .Font.Name = "Arial"
        .Font.Size = 12
    End With

    .[a2] = "Cycles"

    lastRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1

    .Cells(lastRow, 1) = "Release Grand Total"
    .Cells(lastRow, 2).Resize(1, 9).FormulaR1C1 = "=sum(R3C:R[-1]C)"
    
    .Range(.Cells(3, 6), .Cells(lastRow - 1, 9)).FormulaR1C1 = "=IF(RC3=3, 0, RC3/RC2)"
    .Range(.Cells(3, 6), .Cells(lastRow, 9)).Style = "Percent"
    
    '.last
    
    With .Cells(lastRow, 1).Resize(1, 10).Interior
        .Pattern = xlSolid
        .ColorIndex = 37
    End With
    
    Set DataRange = MainWorksheet.UsedRange
    With DataRange.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With DataRange.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With DataRange.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With DataRange.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With DataRange.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With DataRange.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
End With



End Sub

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 8

Expert Comment

by:Kelvin81
ID: 34113337
Ugh, I'm really sorry for all of the posts.  I'm a bit rusty.

I made a mistake in the formulas.  Here's a corrected version.
-K
Sub PostProcessing()
Dim MainWorksheet As Worksheet
' Make sure your worksheet name matches!
Set MainWorksheet = ActiveWorkbook.Worksheets("Have")
Dim DataRange As Range
Dim lastRow As Long
Set DataRange = MainWorksheet.UsedRange
' Now that you have the data in DataRange you can process it.

    MainWorksheet.Range("A1:J1").Font.Bold = True
    MainWorksheet.Range("A1:J1").Interior.ColorIndex = 15


With MainWorksheet
    .Rows(1).Insert

    With .Rows(2)
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With

    With .Range("B1:J1")
        .Merge
        .HorizontalAlignment = xlCenter
        .Font.Bold = True
        .FormulaR1C1 = "Test Execution Sprint View"
        .Font.Name = "Arial"
        .Font.Size = 12
    End With

    .[a2] = "Cycles"

    lastRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1

    .Cells(lastRow, 1) = "Release Grand Total"
    .Cells(lastRow, 2).Resize(1, 9).FormulaR1C1 = "=sum(R3C:R[-1]C)"
    '/ % executed
    .Range(.Cells(3, 6), .Cells(lastRow - 1, 6)).FormulaR1C1 = "=IF(RC3=0, 0, RC3/RC2)"
    '/ % pass of executed
    .Range(.Cells(3, 7), .Cells(lastRow - 1, 7)).FormulaR1C1 = "=IF(RC4=0, 0, RC4/RC3)"
    
    '/ % fail of executed
    .Range(.Cells(3, 8), .Cells(lastRow - 1, 8)).FormulaR1C1 = "=IF(RC5=0, 0, RC5/RC3)"
    
    '/ % pass of total
    .Range(.Cells(3, 9), .Cells(lastRow - 1, 9)).FormulaR1C1 = "=IF(RC4=0, 0, RC4/RC2)"
    
    .Range(.Cells(3, 6), .Cells(lastRow, 9)).Style = "Percent"
    
    '.last
    
    With .Cells(lastRow, 1).Resize(1, 10).Interior
        .Pattern = xlSolid
        .ColorIndex = 37
    End With
    
    Set DataRange = MainWorksheet.UsedRange
    With DataRange.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With DataRange.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With DataRange.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With DataRange.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With DataRange.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With DataRange.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
End With



End Sub

Open in new window

0
 

Author Comment

by:j420exe1
ID: 34114446
It's still putting the sum formula in the last row in each column.  
0
 
LVL 8

Accepted Solution

by:
Kelvin81 earned 2000 total points
ID: 34114586
My appologies, I thought thats what you wanted.

I'm a bit slow.

Here it is with the functions in the last row as well.

Regards,
Kelvin
Sub PostProcessing()
Dim MainWorksheet As Worksheet
' Make sure your worksheet name matches!
Set MainWorksheet = ActiveWorkbook.Worksheets("Have")
Dim DataRange As Range
Dim lastRow As Long
Set DataRange = MainWorksheet.UsedRange
' Now that you have the data in DataRange you can process it.

    MainWorksheet.Range("A1:J1").Font.Bold = True
    MainWorksheet.Range("A1:J1").Interior.ColorIndex = 15


With MainWorksheet
    .Rows(1).Insert

    With .Rows(2)
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With

    With .Range("B1:J1")
        .Merge
        .HorizontalAlignment = xlCenter
        .Font.Bold = True
        .FormulaR1C1 = "Test Execution Sprint View"
        .Font.Name = "Arial"
        .Font.Size = 12
    End With

    .[a2] = "Cycles"

    lastRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1

    .Cells(lastRow, 1) = "Release Grand Total"
    .Cells(lastRow, 2).Resize(1, 9).FormulaR1C1 = "=sum(R3C:R[-1]C)"
    '/ % executed
    .Range(.Cells(3, 6), .Cells(lastRow, 6)).FormulaR1C1 = "=IF(RC3=0, 0, RC3/RC2)"
    '/ % pass of executed
    .Range(.Cells(3, 7), .Cells(lastRow, 7)).FormulaR1C1 = "=IF(RC4=0, 0, RC4/RC3)"
    
    '/ % fail of executed
    .Range(.Cells(3, 8), .Cells(lastRow, 8)).FormulaR1C1 = "=IF(RC5=0, 0, RC5/RC3)"
    
    '/ % pass of total
    .Range(.Cells(3, 9), .Cells(lastRow, 9)).FormulaR1C1 = "=IF(RC4=0, 0, RC4/RC2)"
    
    .Range(.Cells(3, 6), .Cells(lastRow, 9)).Style = "Percent"
    
    '.last
    
    With .Cells(lastRow, 1).Resize(1, 10).Interior
        .Pattern = xlSolid
        .ColorIndex = 37
    End With
    
    Set DataRange = MainWorksheet.UsedRange
    With DataRange.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With DataRange.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With DataRange.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With DataRange.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With DataRange.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With DataRange.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
End With



End Sub

Open in new window

0
 

Author Closing Comment

by:j420exe1
ID: 34115290
Perfect!  Thanks.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question