Solved

Amend code

Posted on 2011-03-07
6
170 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 500 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel Formula 5 43
Remove duplicates using cell values VBA 2 29
Alphabetical Order for Letters 2 21
Turn several entries on single cell, into individual lines 14 26
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

776 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