Solved

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

Posted on 2013-05-16
5
477 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 81

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 81

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

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
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…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

932 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

15 Experts available now in Live!

Get 1:1 Help Now