Solved

Automate Excel Task

Posted on 2012-03-25
3
304 Views
Last Modified: 2012-05-30
Part C:

This is a follow-on from Part B:

http://www.experts-exchange.com/Microsoft/Applications/Q_27647644.html#a37762768


A macro is needed which will look at Col A of tab “Raw Data – copy” and where it finds a “C_Num” which has an alpha character it will:
-       remove that row and write it to a new tab called “CS only”.  
-      Insert row totals and cross-totals
-      Adjust the totals of tab “Raw Data – copy”

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

Accepted Solution

by:
Norie earned 500 total points
ID: 37762928
This can be done with filters.
Option Explicit

Sub FilterDataOnCS()
Dim ws As Worksheet
Dim wsData As Worksheet
Dim wsCSAlpha As Worksheet
Dim wsCSNum As Worksheet
Dim rngData As Range
Dim rngCrit As Range
Dim LastRow As Long

    Set wsData = Worksheets("Raw Data")

    LastRow = wsData.Range("A" & Rows.Count).End(xlUp).Row

    Set rngData = wsData.Range("A1:H" & LastRow)

    Set rngCrit = wsData.Range("P1:P2")

    rngCrit.Cells(1) = "*"

    rngCrit.Cells(2) = "=ISTEXT(A2)"

    Set wsCSAlpha = Worksheets.Add

    wsCSAlpha.Name = "CS Alpha"

    rngData.AdvancedFilter xlFilterCopy, rngCrit, wsCSAlpha.Range("A1")

    Set wsCSNum = Worksheets.Add

    wsCSNum.Name = "CS Number"

    rngCrit.Cells(2) = "=ISNUMBER(A2)"

    rngData.AdvancedFilter xlFilterCopy, rngCrit, wsCSNum.Range("A1")

    rngCrit.ClearContents

    ' add totals to worksheets
    For Each ws In Worksheets(Array("CS Number", "CS Number"))
        Call AddTotals(ws)
    Next ws

End Sub

Open in new window

0
 

Author Comment

by:RishiSingh05
ID: 37762976
The worksheet this macro applies to is "Raw Data - copy" not "Raw Data".  So I guess if I make the change in:  Set wsData = Worksheets("Raw Data")
I should be ok.
0
 
LVL 33

Expert Comment

by:Norie
ID: 37763181
Isn't 'Raw Data - copy' just a copy of 'Raw Data'?

Or is it a copy that's had the JobCost has been removed?

Why not just run the code on the 'Raw Data' worksheet?

Perhaps if you could explain the overall aim that might make things clearer.

Do you want to split out the data from the 'Raw Data' worksheet based on certain criteria?

PS If you do make the change then the code should still work.
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 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