• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Data pull with criteria

Abhijeet

Active Member
Hi

I have macro to pull data with criteria with Trust & Work Type i use advanced filter to pull the data but have so many trust so every time i have to select the trust & pull the data i want what ever trust numbers are reflect in Column S all the trust data pull & save in workbook with 3 sheets Salary,Travel,Absence please tell me how to do this
 

Attachments

  • Advanced Filter.xls
    67.5 KB · Views: 12
Hi Abhijeet ,

Nothing is clear.

Your workbook has data in columns A through M ; you want to transfer this data to columns W through AI ; why ?

Second , you want the data to be transferred to a second set of columns and saved in the same workbook ; why ?

Narayan
 
Narayan sir look the macro S2:T2 i have mention criteria that data i want to transfer in W1:AI1.My problem is i have more than 20 trust & every time i have to select the trust & run the macro & copy paste the data so i want what ever trust numbers are reflect in Column O that single trust data in paste in workbook with 3 sheets that is Salary Travel Absence
 
Hi Abhijeet ,

Why do you need to copy and paste ? The macro is doing that.

As far as I can see you don't need to do anything except change the criteria range depending on the number of trusts that you wish to extract data for.

If there is just one trust , the criteria range will be S1 through T2 ; if there are 2 trusts , it needs to be changed to S1 through T3 , and so on. Even this can be automated.

Can you explain ?

Narayan
 
But i want single trust data in every workbook to copy paste.If i have 3 trust then 3 different workbook i want with the data
 
Hi Abhijeet ,

That means each time you run the macro , new workbooks will be created ; what is the naming convention to be followed for these new workbooks ?

Narayan
 
Hi
i am doing my self to this macro split trust wise Only Travel Seeta data please help me to all 3 Sheets data paste in 1 workbook
 

Attachments

  • Advanced Filter.xls
    72 KB · Views: 1
Here i did for Blank data skip not save in workbook.Please help me all 3 sheets data in Trust wise in workbook to save
 

Attachments

  • Advanced Filter.xls
    72.5 KB · Views: 5
You might interested to check it.

Code:
Option Explicit
Sub Split_Trust_Wise_Data()
    Dim MySheet As Worksheet, ws As Worksheet
    Dim i As Long, N As Workbook
    Dim UList As Collection, UListValue As Variant, c As Integer
    Dim response As Variant
   
Application.ScreenUpdating = False
Application.DisplayAlerts = False

response = MsgBox("Are you ready because files with same name would get replaced.", vbQuestion + vbYesNo)
If response = vbNo Then Exit Sub

c = 5
Set MySheet = ActiveSheet
Set UList = New Collection

    For Each ws In ThisWorkbook.Sheets
        With ws
        On Error Resume Next
            For i = 2 To .Range("A1").CurrentRegion.Rows.Count
                If Len(.Cells(i, c)) > 0 Then UList.Add .Cells(i, c), CStr(.Cells(i, c))
            Next i
        On Error GoTo 0
        End With
    Next

For Each UListValue In UList
Set N = Workbooks.Add(xlWBATWorksheet)
    For Each ws In ThisWorkbook.Sheets
        With ws
            .[S2].Value = UListValue
            If Len(.[S3]) > 0 Then .[S3].Value = UListValue
            .Range("A1").CurrentRegion.AdvancedFilter xlFilterCopy _
                , .Range("S1:T2"), .Range("W1:AI1"), Unique:=False
        End With
            With N
                ws.Range("W1").CurrentRegion.Copy
                Sheets.Add().Name = ws.Name
                Sheets(ws.Name).Paste
                Cells.EntireColumn.AutoFit
            End With
    Next ws
   
    For Each ws In N.Worksheets
        If IsEmpty(ws.[A1]) Then ws.Delete
    Next
    N.SaveAs Filename:=Application.ThisWorkbook.Path & "\" & UListValue.Value
    N.Close False
Set ws = Nothing
Next UListValue

MySheet.Select
MsgBox "DONE-DONE-DONE", vbInformation
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
 
Hi Deepak
If I add in Column S New Trust 348 615 In that data 21,37,58 Trust data also but i am not add in Column S in salary rest of the trust 21,37,58 trust in Column S then No need to save Salary sheets the 21,37,58 trust in these workbooks
 
Last edited:
Hi Deepak
If I add in Column S New Trust 348 615 In that data 21,37,58 Trust data also but i am not add in Column S in salary rest of the trust 21,37,58 trust in Column S then No need to save Salary sheets the 21,37,58 trust in these workbooks

Only as per S2 drop down needs to be exported????
 
Not S2 In column O what ever Trust number only pull & save that trust data.Every Sheet mention in Column O the trust Numbers
 
these are the criteria Actually i use advanced filter in my macro so i used this critera range if u are not use advanced filter then Skip S column Trust but take T column criteria & O column for Trust Numbers
 
these are the criteria Actually i use advanced filter in my macro so i used this critera range if u are not use advanced filter then Skip S column Trust but take T column criteria & O column for Trust Numbers

Check This...

Code:
Option Explicit
Sub Split_Trust_Wise_Data2()
    Dim MySheet As Worksheet, ws As Worksheet
    Dim i As Long, N As Workbook
    Dim UList As Collection, UListValue As Variant, c As Integer
    Dim response As Variant
   
Application.ScreenUpdating = False
Application.DisplayAlerts = False

response = MsgBox("Are you ready because files with same name would get replaced.", vbQuestion + vbYesNo)
If response = vbNo Then Exit Sub

c = 5
Set MySheet = ActiveSheet
Set UList = New Collection

    For Each ws In ThisWorkbook.Sheets
        With ws
        On Error Resume Next
            For i = 2 To .Range("O1").CurrentRegion.Rows.Count
                If Len(.Cells(i, "O")) > 0 Then UList.Add .Cells(i, "O"), CStr(.Cells(i, "O"))
            Next i
        On Error GoTo 0
        End With
    Next

For Each UListValue In UList
Set N = Workbooks.Add(xlWBATWorksheet)
    For Each ws In ThisWorkbook.Sheets
        With ws
            .[S2].Value = UListValue
            If Len(.[S3]) > 0 Then .[S3].Value = UListValue
            .Range("Extract").CurrentRegion.ClearContents
            .Range("A1").CurrentRegion.AdvancedFilter xlFilterCopy, _
                .Range("Criteria"), .Range("Extract")
        End With
            With N
                ws.Range("Extract").CurrentRegion.Copy
                Sheets.Add().Name = ws.Name
                Sheets(ws.Name).Paste
                Cells.EntireColumn.AutoFit
            End With
    Next ws
   
    For Each ws In N.Worksheets
        If IsEmpty(ws.[A1]) Then ws.Delete
    Next
    N.SaveAs Filename:=Application.ThisWorkbook.Path & "\" & UListValue.Value & Format(Now, "dmmmyyyy-hhmmss")
    N.Close False
Set ws = Nothing
Next UListValue

MySheet.Select
MsgBox "DONE-DONE-DONE", vbInformation
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
 

Attachments

  • Advanced Filter (2).xls
    74 KB · Views: 4
Back
Top