Combine macro

SasiKumar007

New Member
Joined
Mar 7, 2023
Messages
1
Office Version
  1. 2010
Platform
  1. Windows
Dear Experts,

I have created macro to open the multiple excel file available on the particular path and apply the filter in second sheet including the blank rows and filter only the values in L column and copy the data to new sheet and paste there . Next file data will paste below to the last row.

Issue :

1 . This macro is working on local drive but file saved in one drive was not working. Pls help to change code to select the file from folder or from onedrive.

2 . Filter not applying after the blank rows and deselecting the blank value in L column , total row is 1K even I have coded to select 50K but not working.

ActiveSheet.Range("$A$2:$J$50000").AutoFilter Field:=10, Criteria1:="<>"

LastRow = .Sheets(2).Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
.Sheets(2).Range("A3:J" & LastRow).Copy wkbDest.Sheets(1).Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
.Close savechanges:=False

-----------------------------------------------------------------------------------------------------------------------
code :

Sub CopyRange()
Application.ScreenUpdating = False
Dim wkbDest As Workbook
Dim wkbSource As Workbook
Set wkbDest = ThisWorkbook
Dim LastRow As Long
Const strPath As String = "C:\Users\sse106\Downloads\EMP WORK PROFILE\"
ChDir strPath
strExtension = Dir("*.xlsx*")
Do While strExtension <> ""
Set wkbSource = Workbooks.Open(strPath & strExtension)
With wkbSource

Sheets("Activity Survey Template").Select

ActiveSheet.Range("$A$2:$J$50000").AutoFilter Field:=10, Criteria1:="<>"

LastRow = .Sheets(2).Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
.Sheets(2).Range("A3:J" & LastRow).Copy wkbDest.Sheets(1).Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
.Close savechanges:=False
End With
strExtension = Dir
Loop
Application.ScreenUpdating = True

Dim ws As Worksheet ' define the sheet you want to work with
Set ws = ThisWorkbook.Worksheets("Output")

' Filter
ActiveSheet.Range("$a$1:$J$1048576").AutoFilter Field:=10, Criteria1:="="


' get filtered data without heading
Dim FilteredRows As Range
On Error Resume Next ' avoid an error message if no rows were filtered
Set FilteredRows = ws.UsedRange.Resize(RowSize:=ws.UsedRange.Rows.Count - 1).Offset(RowOffset:=1).SpecialCells(xlCellTypeVisible)
On Error GoTo 0 ' re-activate error reporting !!!

If Not FilteredRows Is Nothing Then
FilteredRows.EntireRow.Delete
ActiveSheet.AutoFilterMode = False
End If

End Sub
------------------------------------------------------

Data :

Line Manager Employee IDBusiness Segment 2Region Supporting 3L1 RefL1 Description 4L2 Description 4L3 Description 4L4 Description 4% of Role 5
aaa
123​
ALL001Finance Master Data ManagementMaintain Chart of AccountsMaintain Chart of AccountsCreate Group Account
10​
aaa
124​
ALL002Finance Master Data ManagementeFinance Master Data ManagementMaintain Chart of AccountsCreate Group Account
10​
aaa
125​
ALL003Finance Master Data ManagementFinance Master Data ManagementMaintain Chart of AccountsChange Group Account
5​
aaa
126​
ALL005Finance Master Data ManagementFinance Master Data ManagementMaintain Chart of AccountsChange/ Extend Operational G/L Account new
5​
aaa
127​
ALL006Finance Master Data ManagementFinance Master Data ManagementMaintain Cost & Profit CentresCreate Cost Center
10​
aaa
128​
ALL007eeFinance Master Data ManagementeFinance Master Data ManagementMaintain Cost & Profit CentresCreate Profit Center
10​
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,213,549
Messages
6,114,264
Members
448,558
Latest member
aivin

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