Solved

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

Posted on 2013-05-16
5
499 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_
[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
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the 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 will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

724 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