Hi JA00,
Thanks for your help. While trying I am getting the same error as earlier;
See below images of my files. The source files (Data_P en Data_T) are identical and filtered for non empty rows in column 172. The results I want to copy in the currentworkbook below each other with Data_P on top. Ideally the currentworkook should first be cleared starting from row 5. It is not a must because the rows will be more and more, but it would be then perfect.
To complete the picture I have added at the bottom of this message actual code as well .
Thank you
This is the currentworkbook
This is the source workbook;
Actual code:
Sub DataP()
Dim c As Range, rng As Range, rng1 As Range, rng2 As Range, rng3 As Range
Dim i As Long, j As Long, k As Long, m As Long, n As Long
Dim arr() As String, arr1() As Variant, arr2() As Variant
Dim s As String, t As String, shn As String
Dim AC As Long, LR As Long, LC As Long, RN As Long
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim sourceworkbook As Workbook
Dim currentworkbook As Workbook
Set currentworkbook = ThisWorkbook
Set sourceworkbook = Workbooks.Open("
https://parkercorp.sharepoint.com/sites/BusinessManagementSystem159/Shared Documents/Test/Kaizen/2. Shop floor - Orders.xlsm")
ThisWorkbook.Sheets("Data").Activate
ActiveSheet.Unprotect "vst"
shn = "Data_P"
sourceworkbook.Activate
Sheets(shn).Range("A4").AutoFilter Field:=172, Criteria1:="<>", Operator:=xlAnd
Sheets(shn).Range("A4").Select
AC = ActiveCell.Column
RN = ActiveCell.Row
LR = LastRowColumn("R")
LC = LastRowColumn("C")
Set rng = Range(Cells(RN + 1, AC), Cells(LR, AC))
Set rng1 = Range(Cells(RN + 1, AC), Cells(LR, LC))
arr1 = rng1.Value
j = 0
For Each c In rng
If Not c.Rows.Hidden Then
j = j + 1
s = s & c.Row & ", "
End If
Next c
arr = Split(s, ", ")
Set rng2 = Range(Cells(RN, AC), Cells(UBound(arr) + RN - 1, LC + AC - 1))
arr2 = rng2.Value
m = 1
n = 0
For i = LBound(arr1) To UBound(arr1)
For j = LBound(arr1, 2) To UBound(arr1, 2)
If arr
= i + RN Then
arr2(m, j) = arr1(i, j)
Else
GoTo Skip
End If
Next j
m = m + 1
n = n + 1
Skip:
Next i
j = UBound(arr2)
k = UBound(arr2, 2)
currentworkbook.Activate
Worksheets("Data").Activate
Set rng3 = Sheets("Data").Range(Cells(5, 1), Cells(j + 4, k))
rng3.Value = arr2
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub