Solved

Insert Row and Format Excel Cell

Posted on 2013-05-14
4
370 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
  • 2
4 Comments
 
LVL 92

Expert Comment

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

Or even better, a PivotTable?
0
 
LVL 1

Author Comment

by:Idarac
Comment Utility
Can I get the effect I need using the subtotals feature?

Cannot use a pivot table.
0
 
LVL 1

Author Comment

by:Idarac
Comment Utility
I am not familiar with the subtotals feature....
0
 
LVL 31

Accepted Solution

by:
Rob Henson earned 500 total points
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

763 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

6 Experts available now in Live!

Get 1:1 Help Now