Solved

Insert Row and Format Excel Cell

Posted on 2013-05-14
4
402 Views
Last Modified: 2013-05-29
I need an EXCEL VBA example on how to insert a row and format the cells.

On the spreadsheet I have these rows.
      Col A            Col B            Col C
Company A      Winget 1       10,000
Company A      Winget 3        10,000
Company A      Winget 4       20,000
Company A      Winget 5        30,000
Company B      Winget 1       10,000
Company B     Winget 3        20,000
Company B      Winget 4       30,000
Company B     Winget 5        40,000



I want to insert a line below these rows using VBA. Each cell in right justifed, Bolded and the third column cell would sum Col C. The row will be light blue in colour.

The result would look like this  

      Col A            Col B            Col C
Company A      Winget 1       10,000
Company A      Winget 3        10,000
Company A      Winget 4       20,000
Company A      Winget 5        30,000
                            Totals:        60,000
Company B      Winget 1       10,000
Company B     Winget 3        20,000
Company B      Winget 4       30,000
Company B     Winget 5        40,000
                            Totals:       100,000

With each totals row highlighted in blue and all cells bolded and right justified.
0
Comment
Question by:Idarac
[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
  • 2
4 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 39166472
Out of curiosity, why not simply use the Subtotals feature?

Or even better, a PivotTable?
0
 
LVL 1

Author Comment

by:Idarac
ID: 39166523
Can I get the effect I need using the subtotals feature?

Cannot use a pivot table.
0
 
LVL 1

Author Comment

by:Idarac
ID: 39166549
I am not familiar with the subtotals feature....
0
 
LVL 33

Accepted Solution

by:
Rob Henson earned 500 total points
ID: 39167685
Subtotal feature is on the Data menu.

Fairly simple procedure, the only pre-requisite I would suggest you check on before initiating the feature is to check that the column for which you want the totals based on, eg Company in your example, is sorted because the subtotal feature relies on a change in value in a column to insert a row and apply the subtotal.

The subtotal feature will only add the rows with the subtotals, with the wording "Total Company A" or something similar. If you want specific text on the total row, I suspect you could achieve with edit/replace.

The formatting would have to be done separately.

The whole thing could be run through a single macro.

Thanks
Rob H
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

740 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