?
Solved

Amend code

Posted on 2011-03-07
6
Medium Priority
?
178 Views
Last Modified: 2012-05-11
Hi,

Two members of EE kindly provided me some code.

I would like a slight amendment.

Where it subtotals ColF, i would like it to copy the rate from above and paste it down.

E.G instead of F5= 0.00005771 Total

F5= 0.00001924

and so on.

Thanks
Seamus
Example.xls
0
Comment
Question by:Seamus2626
  • 3
  • 3
6 Comments
 
LVL 30

Accepted Solution

by:
SiddharthRout earned 2000 total points
ID: 35058489
Try this

Sub Sample()
    Dim TotColumns()
    Dim I As Long, LastRow As Long
    
    FinalCol = Sheets("Details").Range("A1").End(xlToRight).Column
    
    Application.ScreenUpdating = False
    
    ReDim Preserve TotColumns(1 To FinalCol - 2)
    For I = 3 To FinalCol
        TotColumns(I - 2) = I
    Next I
    
    With Sheets("Details")
        .Range("A1").Subtotal GroupBy:=6, Function:=xlSum, TotalList:=TotColumns, _
        Replace:=True, PageBreaks:=True, SummaryBelowData:=True
    
        LastRow = .Range("A" & Rows.Count).End(xlUp).Row
    
        For I = LastRow To 2 Step -1
            If InStr(1, .Range("B" & I).Value, "Total", vbTextCompare) Then
                .Range("F" & I).Font.Bold = True
                .Range("F" & I).Value = Range("F" & I - 1).Value
                .Range("C" & I).Copy Range("B" & I)
                
                .Rows(I + 1).Select
                Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
            End If
        Next I
    End With
    Application.ScreenUpdating = True
End Sub

Open in new window


Sid
0
 

Author Comment

by:Seamus2626
ID: 35058558
Thats perfect Sid, sorry to be annoying, can you amend so that ColD doesnt subtotal?

Thanks
Seamus
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35058590
Sure. What do you want there? Leave it blank?

Sid
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.

 

Author Comment

by:Seamus2626
ID: 35058612
yep, blank is perfect

Thanks
Seamus
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35058656
Just Add this line

.Range("D" & I).ClearContents

in line 25 in the above code.

Sid
0
 

Author Closing Comment

by:Seamus2626
ID: 35058686
Thanks!!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

864 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