Copy Paste

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,058
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
I am trying to explain this in a best possible way.

I have this file name Daily Performance Tracker V1.xlsm and in sheet name "Dashboard" with cell value in c3
and have downloaded files in folder Daily Performance Downloaded Files (all the file ext is .xlsx),

Trying to create a script were it will open one by one all .xlsx the files from the folder Daily Performance Downloaded Files
1. it will open the file from folder Daily Performance Downloaded Files
2. Then will select the sheet "Event Scheduler"
2. then will do autofilter till the last row (starting from cell d2 to Z2 are headers )
3. Autofilter Criteria:- will be Daily Performance Tracker V1.xlsm sheets("Dashboatd").range("c3").value
its date.
4. Once the date is filter from .xlsx file
5. need to paste only visible cells from .xlsx file to last row of .xlsm file in sheet Actual DailyData
6. It should do this till all the files from folder Daily Performance Downloaded Files are completed.

This code will not do this, any suggestion.

VBA Code:
 Sub copydata()
 
    Windows("Daily Performance Tracker V1.xlsm").Activate
    ActiveWorkbook.Sheets("Actual DailyData").Activate
    Sheets("DownloadFiles").Unprotect "Qtech456$!"
       
    Set wbsource = Workbooks.Open(Application.ActiveWorkbook.Path & "\" & "Daily Performance Downloaded Files" & "\" & Sheets("DownloadFiles").Range("j2").Value)
           
    Windows("abcd-Daily Performance Report.xlsx").Activate
    Sheets("Event Scheduler").Select
    With ActiveSheet
        .AutoFilter = True
        
    End With

End sub
 

Attachments

  • Autofilter Criteria.jpg
    Autofilter Criteria.jpg
    197.6 KB · Views: 9
  • Data need to be copy from.jpg
    Data need to be copy from.jpg
    253 KB · Views: 9
  • Need Data to paste one below the other.jpg
    Need Data to paste one below the other.jpg
    201 KB · Views: 8

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Did it and this code worked all perfect, posting it, if incase any of the person needs it
thanks a ton.

Solved.....

VBA Code:
Sub GetAndOpenFile()
   Dim fPath As String
   Dim fName As String
   Dim fName1 As String
   Dim WB As Workbook
   Dim WB1 As Workbook
   
   Dim ctr As String
   
Set WB1 = ActiveWorkbook    ' you can set the workbook name
Sheets("sheet1").Select 'you can change the sheet name
   
   Dim lastRow As Long
   lastRow = Cells(Rows.Count, "A").End(xlUp).Row

Dim i As Long
    For i = 2 To lastRow
fName1 = Cells(i, "J").Value
   
   
   ctr = WB1.Sheets("sheet1").Range("c2").Value
   'ctr = Workbooks("abc.xlsm").Sheets("Dashboard").Range("c2").Value
   
        On Error Resume Next
        fPath = Application.ActiveWorkbook.Path & "\" & "Folder Name"  'you can change the folder name
        fName = fPath & "\" & fName1 & ".xlsx"
        Set WB = Workbooks.Open(fName)
        
      
        
  With WB
        .Sheets("Sheet1").Select
         Dim lastRow1 As Long
         lastRow1 = Cells(Rows.Count, "E").End(xlUp).Row
        
    With Worksheets("sheet1")
      With .Range("V3:V" & .Range("E" & .Rows.Count).End(xlUp).Row)
           .Formula = "=E3"
           .Value = .Value
           .NumberFormat = "[$-en-US]dd-mm-yyyy;@"
       End With
     End With
        
   With Sheets("sheet1").Range("V2")
        .AutoFilter Field:=1, Criteria1:=ctr
   End With
        
   Range("D2:O" & lastRow1).Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy
   WB1.Activate
   Sheets("sheet4").Select
    Range("A4").Select
    lMaxRows = Cells(Rows.Count, "A").End(xlUp).Row
    Range("A" & lMaxRows + 1).Select
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=False
    Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=False
    'xlPasteFormats
    Application.CutCopyMode = False
    Range("A4").Select

    WB.Activate
    AutoFilter = False
    
    Application.DisplayAlerts = False
     WB.Close
    Application.DisplayAlerts = True
  End With
  
  WB1.Activate
  Sheets("sheet1").Select
   Next i
   Application.DisplayAlerts = False
   WB1.Save
   Application.DisplayAlerts = True
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,864
Messages
6,121,981
Members
449,058
Latest member
oculus

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