Solved

Need to extract cells to  a new workbooks based on a unique criteria in a certain column

Posted on 2013-05-16
5
472 Views
Last Modified: 2013-05-16
Hi

Here is my issue:

Attached workbook contains a sample worksheet. I need to know how to extract the workbooks containing certain criteria

For example:

Column G contains the division
I want the macro to look into column AP first cell and for that cells content extract all details regarding that division into another workbook and save with the division name.

It would look for division A in column G and then copy all related fields for row 17 - 22 since those contain division A then export all those fields including  row 15 and 16 as headers into another workbook and save,


I need an answer very quickly please help

Thanks
ZHR-M04-macro.xlsm
0
Comment
Question by:FAH_
  • 3
  • 2
5 Comments
 
LVL 80

Accepted Solution

by:
byundt earned 500 total points
ID: 39173626
Here is a macro that will export your data:
Sub ExportData()
Dim cel As Range, rg As Range, rgcopy As Range, rgData As Range, rgFilters As Range
Dim wb As Workbook
Dim flPath As String
flPath = Application.GetSaveAsFilename(ActiveWorkbook.FullName, FileFilter:="Excel workbooks (*.xlsx), *.xlsx", _
    Title:="Pick any workbook in the desired folder, then click 'Save'")
If flPath = "False" Then Exit Sub
Application.ScreenUpdating = False
flPath = Left(flPath, InStrRev(flPath, Application.PathSeparator))
With Worksheets("Table")
    Set rg = .Range("DF_Grid_1")
    Set rgData = rg.Offset(1, 0).Resize(rg.Rows.Count - 1, rg.Columns.Count)
    Set rgFilters = .Range("AP16")
    Set rgFilters = Range(rgFilters, rgFilters.End(xlDown))
End With
rgData.Cells(1, 1).AutoFilter
For Each cel In rgFilters
    If cel.Value <> "" Then
        rgData.AutoFilter Field:=2, Criteria1:=cel.Value
        Set rgcopy = rgData.SpecialCells(xlCellTypeVisible)
        If (rgcopy.Rows.Count > 1) Or (rgcopy.Areas.Count > 1) Then
            Set wb = Workbooks.Add
            rg.Copy ActiveSheet.Cells(1, 1)
            wb.SaveAs flPath & cel.Value & ".xlsx", FileFormat:=51
            wb.Close SaveChanges:=False
        End If
    End If
Next
rgData.AutoFilter Field:=2
End Sub

Open in new window

0
 

Author Comment

by:FAH_
ID: 39173639
How could I manipulate so It will export it based on the division name i.e.

AA.xlsx
A.xlsx
B.xlsx

etc
0
 
LVL 80

Expert Comment

by:byundt
ID: 39173662
FAH_,
Did you try the macro?

I anticipated your request, and wrote the macro accordingly.

Brad
0
 

Author Comment

by:FAH_
ID: 39173728
run-time error 1004

no cells were found
0
 

Author Comment

by:FAH_
ID: 39173732
Got it w

It works now


Thanks a lot :)
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
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…

757 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

19 Experts available now in Live!

Get 1:1 Help Now