match sheets names with names in column and populate data

Alaa mg

Active Member
Joined
May 29, 2021
Messages
343
Office Version
  1. 2019
Hello

I want matching names in column B for CUSTOMERS sheets with sheets names have already created and copy data from CUSTOMERS sheets, but without repeat , just replace new copied data when run the macro every time with old data have already copied and ignore column name for each sheet because I have sheet name.

SHEETS.xlsm
ABCDEF
1DATENAMEORDER NOCONDITIONDEBITCREDIT
206/02/2023ALAA-1ORD-001N/H20,000.00
306/02/2023ALAA-1ORD-002M/H20,000.001,000.00
406/02/2023ALAA-2ORD-003MM/N10,000.00
506/02/2023ALAA-1ORD-004B/N2,000.00100.00
606/02/2023ALAA-1ORD-004B/NN100.00
706/02/2023ALAA-2ORD-005T/R1,000.00
806/02/2023ALAA-3ORD-006MNG1,200.00
906/02/2023ALAA-2ORD-007ITSR1,200.00150.00
1006/02/2023ALAA-2ORD-007ITSRI200.00100.00
1106/02/2023ALAA-3ORD-008ITRE200.00
1206/02/2023ALAA-3ORD-009ITRE100.00
1306/02/2023ALAA-3ORD-010ITRE100.00
1406/02/2023ALAA-3ORD-011ITRE1,000.00
1506/02/2023ALAA-3ORD-012ITRE1,200.00
1606/02/2023ALAA-3ORD-013ITRE200.00
1706/02/2023ALAA-3ORD-014ITRE100.0050.00
CUSTOMERS



SHEETS.xlsm
ABCDE
1DATEORDER NOCONDITIONDEBITCREDIT
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
ALAA-1



SHEETS.xlsm
ABCDE
1DATEORDER NOCONDITIONDEBITCREDIT
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
ALAA-2



expected output

SHEETS.xlsm
ABCDE
1DATEORDER NOCONDITIONDEBITCREDIT
206/02/2023ORD-001N/H20,000.00
306/02/2023ORD-002M/H20,000.001,000.00
406/02/2023ORD-004B/N2,000.00100.00
506/02/2023ORD-004B/NN100.00
6
7
8
9
10
11
12
13
14
15
16
17
ALAA-1


SHEETS.xlsm
ABCDE
1DATEORDER NOCONDITIONDEBITCREDIT
206/02/2023ORD-003MM/N10,000.00
306/02/2023ORD-005T/R1,000.00
406/02/2023ORD-007ITSR1,200.00150.00
506/02/2023ORD-007ITSRI200.00100.00
6
7
8
9
10
11
12
13
14
15
16
17
ALAA-2
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try this:

VBA Code:
Sub copy_sheets()
  Dim c As Range, sh As Worksheet, ky As Variant
  
  Set sh = Sheets("CUSTOMERS")
  With CreateObject("scripting.dictionary")
    For Each c In sh.Range("B2", sh.Range("B" & Rows.Count).End(xlUp))
      If c.Value <> "" Then .Item(c.Value) = Empty
    Next c
    For Each ky In .Keys
      If Evaluate("ISREF('" & ky & "'!A1)") Then
        Sheets(ky).Rows("2:" & Rows.Count).ClearContents
        sh.Range("A1").AutoFilter 2, ky
        sh.AutoFilter.Range.Offset(1).Copy Sheets(ky).Range("A2")
      End If
    Next ky
  End With
  sh.Select
  sh.ShowAllData
End Sub
 
Upvote 0
Hi Dante,
thanks for the code , but I think you missed this
and ignore column name for each sheet because I have sheet name.
shouldn't copy the NAME column , also there is problem about border it will delete and make without border after lastrow contain data , may you see the picture ?
SHEETS.xlsm
ABCDEF
1DATEORDER NOCONDITIONDEBITCREDIT
206/02/2023ALAA-1ORD-001N/H20,000.00
306/02/2023ALAA-1ORD-002M/H20,000.001,000.00
406/02/2023ALAA-1ORD-004B/N2,000.00100.00
506/02/2023ALAA-1ORD-004B/NN100.00
6
7
8
9
10
11
12
13
14
15
16
17
ALAA-1
 
Upvote 0
Try:

VBA Code:
Sub copy_sheets()
  Dim c As Range, sh As Worksheet, ky As Variant
  Dim lr As Long
  
  Application.ScreenUpdating = False
  
  Set sh = Sheets("CUSTOMERS")
  If sh.AutoFilterMode Then sh.AutoFilterMode = False
  lr = sh.Range("A" & Rows.Count).End(3).Row
  
  With CreateObject("scripting.dictionary")
    For Each c In sh.Range("B2", sh.Range("B" & Rows.Count).End(xlUp))
      If c.Value <> "" Then .Item(c.Value) = Empty
    Next c
    For Each ky In .Keys
      If Evaluate("ISREF('" & ky & "'!A1)") Then
        
        Sheets(ky).Rows("2:" & Rows.Count).ClearContents
        sh.Range("A1").AutoFilter 2, ky
        sh.Range("A2:A" & lr & ",C2:F" & lr).Copy
        Sheets(ky).Range("A2").PasteSpecial xlPasteValues
        
      End If
    Next ky
  End With
  sh.Select
  sh.ShowAllData
  Application.ScreenUpdating = True
End Sub

🫡
 
Upvote 1
Solution

Forum statistics

Threads
1,215,331
Messages
6,124,312
Members
449,152
Latest member
PressEscape

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