Excel filter some data from other two sheets and copy back
Closed
SAGO_1304
Posts
1
Registration date
Monday October 17, 2022
Status
Member
Last seen
October 17, 2022
-
Oct 17, 2022 at 10:13 AM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Nov 1, 2022 at 12:56 PM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Nov 1, 2022 at 12:56 PM
Related:
- Ms exel
- Transfer data from one excel worksheet to another automatically - Guide
- Mark sheet in excel - Guide
- Tmobile data check - Guide
- Safe search filter - Guide
- Sheets right to left - Guide
1 response
TrowaD
Posts
2921
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
December 27, 2022
552
Nov 1, 2022 at 12:56 PM
Nov 1, 2022 at 12:56 PM
Hi Sago,
Check the following code and see if it performs as expected:
Sub RunMe() Dim mFind, cell As Range Dim fAddress As String Dim cVal, x, lRow As Integer Application.ScreenUpdating = False Sheets("Sheet3").Select Range("E3:Q" & Range("E" & Rows.Count).End(xlUp).Row).Delete For Each cell In Sheets("Sheet3").Range("C3:C" & Range("C2").End(xlDown).Row) With Application.WorksheetFunction cVal = .Max(.CountIf(Sheets("Sheet1").Columns("C"), cell.Value), .CountIf(Sheets("Sheet2").Columns("C"), cell.Value)) End With If cVal = 0 Then GoTo NextCell lRow = Sheets("Sheet3").Range("E" & Rows.Count).End(xlUp).Row With Sheets("Sheet3") x = 0 .Select .Range(Cells(cell.Row, "B"), Cells(cell.Row, "C")).Copy Do x = x + 1 .Range("E" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial Loop Until x = cVal End With x = 1 Set mFind = Sheets("Sheet1").Columns("C").Find(cell.Value) If Not mFind Is Nothing Then fAddress = mFind.Address Do Sheets("Sheet1").Select Sheets("Sheet1").Range(Cells(mFind.Row, "D"), Cells(mFind.Row, "H")).Copy Sheets("Sheet3").Range("G" & lRow + x).PasteSpecial x = x + 1 Set mFind = Sheets("Sheet1").Columns("C").FindNext(mFind) Loop While mFind.Address <> fAddress End If x = 1 Set mFind = Sheets("Sheet2").Columns("C").Find(cell.Value) If Not mFind Is Nothing Then fAddress = mFind.Address Do Sheets("Sheet2").Select Sheets("Sheet2").Range(Cells(mFind.Row, "D"), Cells(mFind.Row, "H")).Copy Sheets("Sheet3").Range("M" & lRow + x).PasteSpecial x = x + 1 Set mFind = Sheets("Sheet2").Columns("C").FindNext(mFind) Loop While mFind.Address <> fAddress End If NextCell: Next cell Application.ScreenUpdating = True End Sub
Best regards,
Trowa