Help required: Filter data and copy it from source workbook, and then create new workboook and paste data in it

aman2059

Board Regular
Joined
Jan 17, 2016
Messages
75
Hi All,

I need help on the below problem. I couldn't not find exact solution in the forum.

I need to filter data in the source workbook, copy that visible data and then open new workbook and paste data in it. Also save new workbook on the given location.

I tried below code but it is useful when we need to copy whole workbook instead of copying on visible data!! I am unable to edit it.

Code:
Sub India()

    Dim FName As String
    Dim FPath As String
    Dim NewBook As Workbook

    FPath = "C:\Users\aman\Desktop\Ideas\process\Master files\testing\India"
    FName = "LearnersinMandateDataExport_India_" & Format(Date, "mmddyyyy") & ".xlsx"

Sheets("Sheet1").Copy    'Creates a new workbook with the copied sheet
    Set NewBook = ActiveWorkbook
       
    If Dir(FPath & "\" & "Kerala_" & FName) <> "" Then
        MsgBox "File " & FPath & "\" & FName & " already exists"
    Else
        NewBook.SaveAs Filename:=FPath & "\" & "India_" & FName
                
    MsgBox "File -  " & FName & "  saved to the defined location"
    End If
    
ActiveWorkbook.Save    

    
End Sub

Thank you
 
Last edited:

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,222,315
Messages
6,165,299
Members
451,950
Latest member
WH2000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top