Save customer's data to another worksheet if not exist

ame21

New Member
Joined
Oct 10, 2021
Messages
8
Office Version
  1. 2013
Platform
  1. Windows
I need a VBA Dictionary code for an invoice sheet that if the customer does not exist in the customer sheet so save the new customer’s info from the invoice sheet to the customer sheet


Invoice sheet:

A11: [customer]

A12: [address]

A13: [city]

A14: [postcode]

A15: [telephone]


Customer sheet

Customer ShopManager Telephone Email Address City Postcode

VBA Code:
Sub newCustomer()
    Dim dict As Object
    Set dict = CreateObject("Scripting.Dictionary")
    
    dim sh1, sh2 As Worksheet
    Set sh1 = ThisWorkbook.Sheets("Customer")
    Set sh4 = ThisWorkbook.Sheets("Invoice")
    
    Dim LastRowSh1,LastRowSh4,arr,arr2 As Long
    LastRowSh1 = sh1.Cells(sh1.Rows.Count, "A").End(xlUp).Row
    LastRowSh4 = sh4.Cells(sh4.Rows.Count, "A").End(xlUp).Row

    arr = sh4.Range(sh4.Cells(1, 1), sh4.Cells(LastRowSh4, 1)).Value2 'load col A of invoices
    arr2 = sh1.Range(sh1.Cells(1, 2), sh1.Cells(LastRowSh1, 7)).Value2 'load col B to G of cust

    With dict
           'VBA Dictionery Code
    End With
    
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,223,910
Messages
6,175,316
Members
452,634
Latest member
cpostell

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