?
Solved

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

Posted on 2013-05-16
5
Medium Priority
?
504 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

762 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