Option Explicit
Public cTr As Integer, NumberOfMerge As Integer, iCount As Integer
Public aIr As Integer, foRce As Integer, oNe As Integer
Public SourceSHT As Worksheet, TargetSHT As Worksheet, wsLoop As Worksheet, SuperSHT As Worksheet
Public wbSource As Workbook, wbTarget As Workbook
Public TargetFileName As String, SourceFileName As String, wsArraySheet As String, iZt As String
Public LastRow As Long, cTrValue As Long, cTr4Loop As Long
Public arrValue() As Variant, arrCount() As Variant
Public rngCell As Range
Sub vladimiratanasiu()
Application.ScreenUpdating = False
Set SourceSHT = ActiveSheet
ActiveSheet.Select
LastRow = Range("C" & Rows.Count).End(xlUp).Row
' Loop used to Get Exact number of Merge Area for the array ReDim
NumberOfMerge = 0
For Each rngCell In Range("A3:A" & Cells(Rows.Count, "C").End(xlUp).Row)
If rngCell.Value <> "" Then
NumberOfMerge = NumberOfMerge + 1
End If
Next
'Redim arrMergeValue for Value of Merge Area
ReDim arrValue(NumberOfMerge)
'arrCount Used to store Number of Rows per Merge Value
ReDim arrCount(NumberOfMerge)
foRce = 1
For Each rngCell In Range("A3:A" & Cells(Rows.Count, "C").End(xlUp).Row)
If rngCell.Value <> "" Then
'Get the Value of MergeArea
arrValue(foRce) = rngCell.MergeArea(1).Value
'Get the Number of Rows for said Merge Area
arrCount(foRce) = rngCell.MergeArea.Count
foRce = foRce + 1
End If
Next
' Used to get the number of Merge Value
foRce = foRce - 1
TargetFileName = ActiveWorkbook.Path & "\TARGET.xlsx"
Set wbTarget = Workbooks.Open(TargetFileName)
ActiveWindow.WindowState = xlMaximized
For oNe = 1 To foRce
For Each wsLoop In wbTarget.Sheets
If arrValue(oNe) = wsLoop.Name Then
aIr = 6
Do While aIr <= LastRow
cTr = 7
If IsEmpty(SourceSHT.Range("C" & aIr)) Then
Else
Do While cTr <= LastRow
If SourceSHT.Cells(aIr, 3).Value = wsLoop.Cells(cTr, 2).Value Then
wsLoop.Range("C" & cTr).Value = SourceSHT.Range("D" & aIr).Value
wsLoop.Range("E" & cTr).Value = SourceSHT.Range("E" & aIr).Value
wsLoop.Range("G" & cTr).Value = SourceSHT.Range("F" & aIr).Value
End If
cTr = cTr + 1
Loop
End If
aIr = aIr + 1
Loop
End If
Next
Next
Application.ScreenUpdating = True
MsgBox "Processing Completed....", vbInformation + vbOKOnly, ".:: vladimiratanasiu ::."
End Sub