Solved

Automate Excel tasks

Posted on 2012-03-25
3
338 Views
Last Modified: 2012-03-25
So that I can award more points, I am breaking down my requirements into several parts.  Please refer to the attached Excel file.

Part A:
 I would like a macro which:
-      Formats the numbers in Cols E to H as numbers with 1000 separator (,) and  no decimal places
-      Inserts column totals in Cols E to H
-      Inserts cross-totals in Col I

Thanks.
Book1.xlsx
0
Comment
Question by:RishiSingh05
  • 2
3 Comments
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
ID: 37762672
I wasn't 100% sure what you meant by cross-sums but I've added a formula in each row of I that sums columsn E to H.


Also, I wasn't sure if you wanted that sum to also include the row with the column sums, if you do use this.
    Set rng = Range("I2:I" & LastRow+1)
    

Open in new window


Anyway, here's the code.
Dim rng As Range
Dim LastRow As Long

    LastRow = Range("A" & Rows.Count).End(xlUp).Row
    
    Set rng = Range("E2:H" & LastRow)
    
    rng.NumberFormat = "#,000"
    
    Set rng = Range("E" & LastRow + 1 & ":H" & LastRow + 1)
    
    rng.Formula = "=SUM(R2C:R[-1]C)"
    
    
    Set rng = Range("I2:I" & LastRow)
    
    rng.Formula = "=SUM(E2:H2)"

Open in new window

0
 

Author Comment

by:RishiSingh05
ID: 37762678
Thanks.  I will test it out and let you know.
0
 

Author Comment

by:RishiSingh05
ID: 37762682
I will post Part B shortly.  Thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Office.Com /myAccount 9 39
Multi-user Excel not reflecting who actually has the file opened 10 30
Excel file not created as expected 7 46
Excel 2016 formulas 5 24
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.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

919 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now