Changes required in VBA code

Zubair

Active Member
Joined
Jul 4, 2009
Messages
304
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I have 2 Input tabs 1. Purchase and 2. Sales
Output is transferred to Database & AP for Purchase and Database & AR for Sales

Changes are required as follows:

Database - Cartage to appear 1 time per document, currently appearing based on the Brand row input.

AP - Single entry required, currently appearing based on brand row input.
AR - Single entry required, currently appearing based on brand row input.

Please help to change the VBA code


Purchase
Test 2.xlsm
ABCDEFGHIJKLMNO
1PurchasePU
2Purchase Reel Data Entry Form
3
4
5LocationProductReel
6Reel
7Supplier NameInvoice/Bill No.
8
9Rate selectionInvoice Date
10
11Document No.BrandGramWeightSizeQuantityRate Amount
12-
13-
14-
15-
16-
17-
18-
19-
20-
21-
22-
23-
24-
25-
26-
27-
28-
29-
30-
31-
32-
33-
34-
35-
36RemarksSubtotal-
37Vehicle No.Cartage
38Driver NameTotal-
39
40
41
Purchase Reel
Cell Formulas
RangeFormula
L12:L35L12=IFERROR(+J12*K12*H12,"")
L36L36=SUM(L12:L35)
L38L38=+L36+L37


Sales
Test 2.xlsm
ABCDEFGHIJKLMNO
1SalesSA
2Reel Sales Data Entry Form
3
4
5LocationProductReel
6Reel
7Customer NameInvoice/Bill No.
8
9Rate SelectionInvoice Date
10
11Document No.BrandGramWeightSizeQuantityRateAmount
12-
13-
14-
15-
16-
17-
18-
19-
20-
21-
22-
23-
24-
25-
26-
27-
28-
29-
30-
31-
32-
33-
34-
35-
36RemarksSubtotal-
37Vehicle No.Cartage
38Driver NameTOTAL-
39
40
41
Sales Reel
Cell Formulas
RangeFormula
L12:L35L12=IFERROR(+J12*K12*H12,"")
L36L36=SUM(L12:L35)
L38L38=+L37+L36


Database
Test 2.xlsm
ABCDEFGHIJKLMNOPQRSTUV
1Document No.Document typeTransactionSupplier/Customer NameInvoice No.Invoice DateBrandGramWeightSizeQuantityRate Amount Cartage Vehicle No.Driver NameUser IDTransaction DateRate SelectionRemarksProductLocation To
25600001PUPurchaseSupplier No.110011/1/2020Alpha Kraft101740211001259,250,00058,400 JX8070 Driver 1ZESSA-Click18-04-2022 15:11:28From the price listReelFactory 1
35600001PUPurchaseSupplier No.110011/1/2020Box Board1027412320010014,820,00058,400 JX8070 Driver 1ZESSA-Click18-04-2022 15:11:28From the price listReelFactory 1
45600001PUPurchaseSupplier No.110011/1/2020Delta1037422525010218,921,00058,400 JX8070 Driver 1ZESSA-Click18-04-2022 15:11:28From the price listReelFactory 1
55600001PUPurchaseSupplier No.110011/1/2020Liner10475227140677,053,76058,400 JX8070 Driver 1ZESSA-Click18-04-2022 15:11:28From the price listReelFactory 1
68600001SASalesCustomer No.120011/1/2020Alpha Kraft10174021102051,517,00054,200 JX8000 Driver 2ZESSA-Click18-04-2022 15:14:16From the price listReelFactory 1
78600001SASalesCustomer No.120011/1/2020Box Board10274123151751,945,12554,200 JX8000 Driver 2ZESSA-Click18-04-2022 15:14:16From the price listReelFactory 1
88600001SASalesCustomer No.120011/1/2020Delta10374225251803,339,00054,200 JX8000 Driver 2ZESSA-Click18-04-2022 15:14:17From the price listReelFactory 1
95600002PUPurchaseSupplier No.210051/2/2022Box Board10070025150707,350,00050,000 JX8950 Driver No.5ZESSA-Click19-04-2022 00:00:27ManualChecking the transfer of dataReelFactory 1
105600002PUPurchaseSupplier No.210051/2/2022Dubai10275022130787,605,00050,000 JX8950 Driver No.5ZESSA-Click19-04-2022 00:00:27ManualChecking the transfer of dataReelFactory 1
118600002SASalesCustomer No.4100620/02/2022Liner1047522750903,384,000952,000 JX9820 Driver No.9ZESSA-Click19-04-2022 00:04:13ManualChecking sales data transferReelFactory 1
128600002SASalesCustomer No.4100620/02/2022Delta1037452510015011,175,000952,000 JX9820 Driver No.9ZESSA-Click19-04-2022 00:04:13ManualChecking sales data transferReelFactory 1
135600003PUPurchaseSupplier No.3100920/03/2022Delta1007402510018013,320,000560,000 JX9000 Driver No.10ZESSA-Click20-04-2022 14:01:01ManualChecking the data transferReelFactory 2
145600003PUPurchaseSupplier No.3100920/03/2022Liner101741261509110,114,650560,000 JX9000 Driver No.10ZESSA-Click20-04-2022 14:01:01ManualChecking the data transferReelFactory 2
155600003PUPurchaseSupplier No.3100920/03/2022Dubai102742271808010,684,800560,000 JX9000 Driver No.10ZESSA-Click20-04-2022 14:01:01ManualChecking the data transferReelFactory 2
168600003SASalesCustomer No.11100820/04/2022Dubai10274227151802,003,400540,000 JX8900 Driver No.11ZESSA-Click20-04-2022 14:44:21ManualCheck transactions to other tabsReelFactory 2
178600003SASalesCustomer No.11100820/04/2022Liner10174126201902,815,800540,000 JX8900 Driver No.11ZESSA-Click20-04-2022 14:44:21ManualCheck transactions to other tabsReelFactory 2
Database


AP
Test 2.xlsm
ABCDEFGHIJKLMNOP
1Document No.Document typeTransactionSupplier/Customer NameInvoice No.Invoice Date Subtotal Cartage Amount Vehicle No.Driver NameUser ID Transaction Date Remarks ProductLocation To
25600001PUPurchaseSupplier No.110011/1/202050,044,76058,40050,103,160JX8070Driver 1ZESSA-Click 18-04-2022 15:11:28 ReelFactory 1
35600001PUPurchaseSupplier No.110011/1/202050,044,76058,40050,103,160JX8070Driver 1ZESSA-Click 18-04-2022 15:11:28 ReelFactory 1
45600001PUPurchaseSupplier No.110011/1/202050,044,76058,40050,103,160JX8070Driver 1ZESSA-Click 18-04-2022 15:11:28 ReelFactory 1
55600001PUPurchaseSupplier No.110011/1/202050,044,76058,40050,103,160JX8070Driver 1ZESSA-Click 18-04-2022 15:11:28 ReelFactory 1
65600002PUPurchaseSupplier No.210051/2/202214,955,00050,00015,005,000JX8950Driver No.5ZESSA-Click 19-04-2022 00:00:27 ReelFactory 1
75600002PUPurchaseSupplier No.210051/2/202214,955,00050,00015,005,000JX8950Driver No.5ZESSA-Click 19-04-2022 00:00:27 ReelFactory 1
85600003PUPurchaseSupplier No.3100920/03/202234,119,450560,00034,679,450JX9000Driver No.10ZESSA-Click 20-04-2022 14:01:01 Checking the data transfer ReelFactory 2
95600003PUPurchaseSupplier No.3100920/03/202234,119,450560,00034,679,450JX9000Driver No.10ZESSA-Click 20-04-2022 14:01:01 Checking the data transfer ReelFactory 2
105600003PUPurchaseSupplier No.3100920/03/202234,119,450560,00034,679,450JX9000Driver No.10ZESSA-Click 20-04-2022 14:01:01 Checking the data transfer ReelFactory 2
AP



AR
Test 2.xlsm
ABCDEFGHIJKLMNOP
1Document No.Document typeTransactionSupplier/Customer NameInvoice No.Invoice Date Subtotal Cartage Amount Vehicle No.Driver NameUser ID Transaction Date RemarksProductLocation To
28600001SASalesCustomer No.120011/1/20206,801,12554,2006,855,325JX8000Driver 2ZESSA-Click 18-04-2022 15:14:16 ReelFactory 1
38600001SASalesCustomer No.120011/1/20206,801,12554,2006,855,325JX8000Driver 2ZESSA-Click 18-04-2022 15:14:16 ReelFactory 1
48600001SASalesCustomer No.120011/1/20206,801,12554,2006,855,325JX8000Driver 2ZESSA-Click 18-04-2022 15:14:17 ReelFactory 1
58600002SASalesCustomer No.4100620/02/202214,559,000952,00015,511,000JX9820Driver No.9ZESSA-Click 19-04-2022 00:04:13 Checking sales data transferReelFactory 1
68600002SASalesCustomer No.4100620/02/202214,559,000952,00015,511,000JX9820Driver No.9ZESSA-Click 19-04-2022 00:04:13 Checking sales data transferReelFactory 1
78600003SASalesCustomer No.11100820/04/20224,819,200540,0005,359,200JX8900Driver No.11ZESSA-Click 20-04-2022 14:44:21 Check transactions to other tabsReelFactory 2
88600003SASalesCustomer No.11100820/04/20224,819,200540,0005,359,200JX8900Driver No.11ZESSA-Click 20-04-2022 14:44:21 Check transactions to other tabsReelFactory 2
AR



Purchase Module
Sub SaveNewDataPurchaseReel()
Application.ScreenUpdating = False
Dim LastRow As Long, srcWS As Worksheet, desWS As Worksheet, brand As Range
Set srcWS = Sheets("Purchase Reel")
Set desWS = Sheets("Database")
Set abcWS = Sheets("AP")
With srcWS

For Each brand In .Range("E12", .Range("E" & .Rows.Count).End(xlUp))
LastRow = desWS.Range("E" & .Rows.Count).End(xlUp).Row + 1

desWS.Range("A" & LastRow).Resize(, 1).Value = Array(.Range("D12"))
desWS.Range("B" & LastRow).Resize(, 2).Value = Array(.Range("O1"), .Range("N1"))
desWS.Range("D" & LastRow).Resize(, 3).Value = Array(.Range("F7"), .Range("J7"), .Range("J9"))
desWS.Range("G" & LastRow).Value = .Range("E" & brand.Row)
desWS.Range("H" & LastRow).Resize(, 6).Value = .Range("G" & brand.Row).Resize(, 6).Value
desWS.Range("N" & LastRow).Resize(, 5).Value = Array(.Range("L37"), .Range("I37"), .Range("I38"), Application.UserName, [Text(Now(), "DD-MM-YYYY HH:MM:SS")])
desWS.Range("S" & LastRow).Resize(, 1).Value = Array(.Range("F9"))
desWS.Range("T" & LastRow).Resize(, 1).Value = Array(.Range("H36"))
desWS.Range("U" & LastRow).Resize(, 1).Value = Array(.Range("J5"))
desWS.Range("V" & LastRow).Resize(, 1).Value = Array(.Range("F5"))


LastRow = abcWS.Range("E" & .Rows.Count).End(xlUp).Row + 1

abcWS.Range("A" & LastRow).Resize(, 1).Value = Array(.Range("D12"))
abcWS.Range("B" & LastRow).Resize(, 2).Value = Array(.Range("O1"), .Range("N1"))
abcWS.Range("D" & LastRow).Resize(, 3).Value = Array(.Range("F7"), .Range("J7"), .Range("J9"))
abcWS.Range("G" & LastRow).Resize(, 7).Value = Array(.Range("L36"), .Range("L37"), .Range("L38"), .Range("I37"), .Range("I38"), Application.UserName, [Text(Now(), "DD-MM-YYYY HH:MM:SS")])
abcWS.Range("N" & LastRow).Resize(, 1).Value = Array(.Range("H36"))
abcWS.Range("O" & LastRow).Resize(, 1).Value = Array(.Range("J5"))
abcWS.Range("P" & LastRow).Resize(, 1).Value = Array(.Range("F5"))


Next brand
End With
Call ResetPurchaseReel
Application.ScreenUpdating = True
End Sub

Sub ResetPurchaseReel()
Application.ScreenUpdating = False
Dim srcWS As Worksheet, desWS As Worksheet
Set srcWS = Sheets("Purchase Reel")
Set desWS = Sheets("Database")
With srcWS
.Range("F5,F7,F9,J7,J9").Interior.Color = xlNone
.Range("F5,F7,F9,J7,J9").Value = ""
.Range("D12:K35").Interior.Color = xlNone
.Range("D12:K35").Value = ""
.Range("I37:I38,L37,H36").Interior.Color = xlNone
.Range("I37:I38,L37,H36").Value = ""
End With
Application.ScreenUpdating = True
End Sub

Sales Module
Sub SaveNewDataSalesReel()
Application.ScreenUpdating = False
Dim LastRow As Long, scrsWS As Worksheet, desWS As Worksheet, brand As Range
Set scrsWS = Sheets("Sales Reel")
Set desWS = Sheets("Database")
Set sreWS = Sheets("AR")
With scrsWS
For Each brand In .Range("E12", .Range("E" & .Rows.Count).End(xlUp))
LastRow = desWS.Range("E" & .Rows.Count).End(xlUp).Row + 1

desWS.Range("A" & LastRow).Resize(, 1).Value = Array(.Range("D12"))
desWS.Range("B" & LastRow).Resize(, 2).Value = Array(.Range("O1"), .Range("N1"))
desWS.Range("D" & LastRow).Resize(, 3).Value = Array(.Range("F7"), .Range("J7"), .Range("J9"))
desWS.Range("G" & LastRow).Value = .Range("E" & brand.Row)
desWS.Range("H" & LastRow).Resize(, 6).Value = .Range("G" & brand.Row).Resize(, 6).Value
desWS.Range("N" & LastRow).Resize(, 5).Value = Array(.Range("L37"), .Range("I37"), .Range("I38"), Application.UserName, [Text(Now(), "DD-MM-YYYY HH:MM:SS")])
desWS.Range("S" & LastRow).Value = .Range("F9")
desWS.Range("T" & LastRow).Value = .Range("H36")
desWS.Range("U" & LastRow).Value = .Range("J5")
desWS.Range("V" & LastRow).Value = .Range("F5")

LastRow = sreWS.Range("E" & .Rows.Count).End(xlUp).Row + 1

sreWS.Range("A" & LastRow).Resize(, 1).Value = Array(.Range("D12"))
sreWS.Range("B" & LastRow).Resize(, 2).Value = Array(.Range("O1"), .Range("N1"))
sreWS.Range("D" & LastRow).Resize(, 3).Value = Array(.Range("F7"), .Range("J7"), .Range("J9"))
sreWS.Range("G" & LastRow).Resize(, 7).Value = Array(.Range("L36"), .Range("L37"), .Range("L38"), .Range("I37"), .Range("I38"), Application.UserName, [Text(Now(), "DD-MM-YYYY HH:MM:SS")])
sreWS.Range("N" & LastRow).Resize(, 1).Value = Array(.Range("H36"))
sreWS.Range("O" & LastRow).Resize(, 1).Value = Array(.Range("J5"))
sreWS.Range("P" & LastRow).Resize(, 1).Value = Array(.Range("F5"))

Next brand
End With
Call ResetSalesReel
Application.ScreenUpdating = True
End Sub

Sub ResetSalesReel()
Application.ScreenUpdating = False
Dim scrsWS As Worksheet, desWS As Worksheet
Set scrsWS = Sheets("Sales Reel")
Set desWS = Sheets("Database")
With scrsWS
.Range("F5,F7,F9,J7,J9").Interior.Color = xlNone
.Range("F5,F7,F9,J7,J9").Value = ""
.Range("D12:K35").Interior.Color = xlNone
.Range("D12:K35").Value = ""
.Range("H36,I37,I38,L37").Interior.Color = xlNone
.Range("H36,I37,I38,L37").Value = ""

End With
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
If I understand correctly, you only want a single record in the database and a single record in AP. But I'm not sure what data goes in columns G to M in the database sheet. Try the following macro for DataPurchaseReel

VBA Code:
'Purchase Module
Sub SaveNewDataPurchaseReel()
  Application.ScreenUpdating = True
  Dim LastRow As Long, srcWS As Worksheet, desWS As Worksheet, brand As Range
  Set srcWS = Sheets("Purchase Reel")
  Set desWS = Sheets("Database")
  Set abcWS = Sheets("AP")
  With srcWS
  'For Each brand In .Range("E12", .Range("E" & .Rows.Count).End(xlUp))
    LastRow = desWS.Range("E" & .Rows.Count).End(xlUp).Row + 1
    
    desWS.Range("A" & LastRow).Resize(, 1).Value = Array(.Range("D12"))
    desWS.Range("B" & LastRow).Resize(, 2).Value = Array(.Range("O1"), .Range("N1"))
    desWS.Range("D" & LastRow).Resize(, 3).Value = Array(.Range("F7"), .Range("J7"), .Range("J9"))
'    desWS.Range("G" & LastRow).Value = .Range("E" & brand.Row)
'    desWS.Range("H" & LastRow).Resize(, 6).Value = .Range("G" & brand.Row).Resize(, 6).Value
    desWS.Range("N" & LastRow).Resize(, 5).Value = Array(.Range("L37"), .Range("I37"), .Range("I38"), Application.UserName, [Text(Now(), "DD-MM-YYYY HH:MM:SS")])
    desWS.Range("S" & LastRow).Resize(, 1).Value = Array(.Range("F9"))
    desWS.Range("T" & LastRow).Resize(, 1).Value = Array(.Range("H36"))
    desWS.Range("U" & LastRow).Resize(, 1).Value = Array(.Range("J5"))
    desWS.Range("V" & LastRow).Resize(, 1).Value = Array(.Range("F5"))
    
    LastRow = abcWS.Range("E" & .Rows.Count).End(xlUp).Row + 1
    
    abcWS.Range("A" & LastRow).Resize(, 1).Value = Array(.Range("D12"))
    abcWS.Range("B" & LastRow).Resize(, 2).Value = Array(.Range("O1"), .Range("N1"))
    abcWS.Range("D" & LastRow).Resize(, 3).Value = Array(.Range("F7"), .Range("J7"), .Range("J9"))
    abcWS.Range("G" & LastRow).Resize(, 7).Value = Array(.Range("L36"), .Range("L37"), .Range("L38"), .Range("I37"), .Range("I38"), Application.UserName, [Text(Now(), "DD-MM-YYYY HH:MM:SS")])
    abcWS.Range("N" & LastRow).Resize(, 1).Value = Array(.Range("H36"))
    abcWS.Range("O" & LastRow).Resize(, 1).Value = Array(.Range("J5"))
    abcWS.Range("P" & LastRow).Resize(, 1).Value = Array(.Range("F5"))
  'Next brand
  End With
  Call ResetPurchaseReel
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
If I understand correctly, you only want a single record in the database and a single record in AP. But I'm not sure what data goes in columns G to M in the database sheet. Try the following macro for DataPurchaseReel

VBA Code:
'Purchase Module
Sub SaveNewDataPurchaseReel()
  Application.ScreenUpdating = True
  Dim LastRow As Long, srcWS As Worksheet, desWS As Worksheet, brand As Range
  Set srcWS = Sheets("Purchase Reel")
  Set desWS = Sheets("Database")
  Set abcWS = Sheets("AP")
  With srcWS
  'For Each brand In .Range("E12", .Range("E" & .Rows.Count).End(xlUp))
    LastRow = desWS.Range("E" & .Rows.Count).End(xlUp).Row + 1
   
    desWS.Range("A" & LastRow).Resize(, 1).Value = Array(.Range("D12"))
    desWS.Range("B" & LastRow).Resize(, 2).Value = Array(.Range("O1"), .Range("N1"))
    desWS.Range("D" & LastRow).Resize(, 3).Value = Array(.Range("F7"), .Range("J7"), .Range("J9"))
'    desWS.Range("G" & LastRow).Value = .Range("E" & brand.Row)
'    desWS.Range("H" & LastRow).Resize(, 6).Value = .Range("G" & brand.Row).Resize(, 6).Value
    desWS.Range("N" & LastRow).Resize(, 5).Value = Array(.Range("L37"), .Range("I37"), .Range("I38"), Application.UserName, [Text(Now(), "DD-MM-YYYY HH:MM:SS")])
    desWS.Range("S" & LastRow).Resize(, 1).Value = Array(.Range("F9"))
    desWS.Range("T" & LastRow).Resize(, 1).Value = Array(.Range("H36"))
    desWS.Range("U" & LastRow).Resize(, 1).Value = Array(.Range("J5"))
    desWS.Range("V" & LastRow).Resize(, 1).Value = Array(.Range("F5"))
   
    LastRow = abcWS.Range("E" & .Rows.Count).End(xlUp).Row + 1
   
    abcWS.Range("A" & LastRow).Resize(, 1).Value = Array(.Range("D12"))
    abcWS.Range("B" & LastRow).Resize(, 2).Value = Array(.Range("O1"), .Range("N1"))
    abcWS.Range("D" & LastRow).Resize(, 3).Value = Array(.Range("F7"), .Range("J7"), .Range("J9"))
    abcWS.Range("G" & LastRow).Resize(, 7).Value = Array(.Range("L36"), .Range("L37"), .Range("L38"), .Range("I37"), .Range("I38"), Application.UserName, [Text(Now(), "DD-MM-YYYY HH:MM:SS")])
    abcWS.Range("N" & LastRow).Resize(, 1).Value = Array(.Range("H36"))
    abcWS.Range("O" & LastRow).Resize(, 1).Value = Array(.Range("J5"))
    abcWS.Range("P" & LastRow).Resize(, 1).Value = Array(.Range("F5"))
  'Next brand
  End With
  Call ResetPurchaseReel
  Application.ScreenUpdating = True
End Sub
Hi DanteAmor - Many thanks, the revised code you provided in ok for AP showing single record but for database I need all rows and single amount of cartage in 1st line like follows :


Database
Test 2.xlsm
ABCDEFGHIJKLMNOPQRSTUV
1Document No.Document typeTransactionSupplier/Customer NameInvoice No.Invoice DateBrandGramWeightSizeQuantityRate Amount Cartage Vehicle No.Driver NameUser IDTransaction DateRate SelectionRemarksProductLocation To
25600001PUPurchaseSupplier No.110011/1/2020Alpha Kraft101740211001259,250,00058,400 JX8070 Driver 1ZESSA-Click18-04-2022 15:11:28From the price listReelFactory 1
35600001PUPurchaseSupplier No.110011/1/2020Box Board1027412320010014,820,000 JX8070 Driver 1ZESSA-Click18-04-2022 15:11:28From the price listReelFactory 1
45600001PUPurchaseSupplier No.110011/1/2020Delta1037422525010218,921,000 JX8070 Driver 1ZESSA-Click18-04-2022 15:11:28From the price listReelFactory 1
55600001PUPurchaseSupplier No.110011/1/2020Liner10475227140677,053,760 JX8070 Driver 1ZESSA-Click18-04-2022 15:11:28From the price listReelFactory 1
Database


AP

Test 2.xlsm
ABCDEFGHIJKLMNOP
1Document No.Document typeTransactionSupplier/Customer NameInvoice No.Invoice Date Subtotal Cartage Amount Vehicle No.Driver NameUser ID Transaction Date Remarks ProductLocation To
25600001PUPurchaseSupplier No.110011/1/202050,044,76058,40050,103,160JX8070Driver 1ZESSA-Click 18-04-2022 15:11:28 ReelFactory 1
AP


Same for AR
 
Upvote 0
Here is the updated code.
VBA Code:
'Purchase Module
Sub SaveNewDataPurchaseReel()
  Application.ScreenUpdating = True
  Dim LastRow As Long, brand As Range
  Dim abcWS As Worksheet, srcWS As Worksheet, desWS As Worksheet
  Set srcWS = Sheets("Purchase Reel")
  Set desWS = Sheets("Database")
  Set abcWS = Sheets("AP")
  With srcWS
    For Each brand In .Range("E12", .Range("E" & .Rows.Count).End(xlUp))
      LastRow = desWS.Range("E" & .Rows.Count).End(xlUp).Row + 1
      desWS.Range("A" & LastRow).Resize(, 1).Value = Array(.Range("D12"))
      desWS.Range("B" & LastRow).Resize(, 2).Value = Array(.Range("O1"), .Range("N1"))
      desWS.Range("D" & LastRow).Resize(, 3).Value = Array(.Range("F7"), .Range("J7"), .Range("J9"))
      desWS.Range("G" & LastRow).Value = .Range("E" & brand.Row)
      desWS.Range("H" & LastRow).Resize(, 6).Value = .Range("G" & brand.Row).Resize(, 6).Value
      desWS.Range("N" & LastRow).Resize(, 5).Value = Array(.Range("L37"), .Range("I37"), .Range("I38"), Application.UserName, [Text(Now(), "DD-MM-YYYY HH:MM:SS")])
      desWS.Range("S" & LastRow).Resize(, 1).Value = Array(.Range("F9"))
      desWS.Range("T" & LastRow).Resize(, 1).Value = Array(.Range("H36"))
      desWS.Range("U" & LastRow).Resize(, 1).Value = Array(.Range("J5"))
      desWS.Range("V" & LastRow).Resize(, 1).Value = Array(.Range("F5"))
    Next brand
  
    LastRow = abcWS.Range("E" & .Rows.Count).End(xlUp).Row + 1
    abcWS.Range("A" & LastRow).Resize(, 1).Value = Array(.Range("D12"))
    abcWS.Range("B" & LastRow).Resize(, 2).Value = Array(.Range("O1"), .Range("N1"))
    abcWS.Range("D" & LastRow).Resize(, 3).Value = Array(.Range("F7"), .Range("J7"), .Range("J9"))
    abcWS.Range("G" & LastRow).Resize(, 7).Value = Array(.Range("L36"), .Range("L37"), .Range("L38"), .Range("I37"), .Range("I38"), Application.UserName, [Text(Now(), "DD-MM-YYYY HH:MM:SS")])
    abcWS.Range("N" & LastRow).Resize(, 1).Value = Array(.Range("H36"))
    abcWS.Range("O" & LastRow).Resize(, 1).Value = Array(.Range("J5"))
    abcWS.Range("P" & LastRow).Resize(, 1).Value = Array(.Range("F5"))
  End With
  Call ResetPurchaseReel
  Application.ScreenUpdating = True
End Sub

Sub ResetPurchaseReel()
  Dim srcWS As Worksheet
  Set srcWS = Sheets("Purchase Reel")
  With srcWS
    .Range("F5,F7,F9,J7,J9").Interior.Color = xlNone
    .Range("F5,F7,F9,J7,J9").Value = ""
    .Range("D12:K35").Interior.Color = xlNone
    .Range("D12:K35").Value = ""
    .Range("I37:I38,L37,H36").Interior.Color = xlNone
    .Range("I37:I38,L37,H36").Value = ""
  End With
End Sub

'Sales Module
Sub SaveNewDataSalesReel()
  Application.ScreenUpdating = False
  Dim sreWS As Worksheet, scrsWS As Worksheet, desWS As Worksheet
  Dim LastRow As Long, brand As Range
  
  Set scrsWS = Sheets("Sales Reel")
  Set desWS = Sheets("Database")
  Set sreWS = Sheets("AR")
  With scrsWS
    For Each brand In .Range("E12", .Range("E" & .Rows.Count).End(xlUp))
      LastRow = desWS.Range("E" & .Rows.Count).End(xlUp).Row + 1
      desWS.Range("A" & LastRow).Resize(, 1).Value = Array(.Range("D12"))
      desWS.Range("B" & LastRow).Resize(, 2).Value = Array(.Range("O1"), .Range("N1"))
      desWS.Range("D" & LastRow).Resize(, 3).Value = Array(.Range("F7"), .Range("J7"), .Range("J9"))
      desWS.Range("G" & LastRow).Value = .Range("E" & brand.Row)
      desWS.Range("H" & LastRow).Resize(, 6).Value = .Range("G" & brand.Row).Resize(, 6).Value
      desWS.Range("N" & LastRow).Resize(, 5).Value = Array(.Range("L37"), .Range("I37"), .Range("I38"), Application.UserName, [Text(Now(), "DD-MM-YYYY HH:MM:SS")])
      desWS.Range("S" & LastRow).Value = .Range("F9")
      desWS.Range("T" & LastRow).Value = .Range("H36")
      desWS.Range("U" & LastRow).Value = .Range("J5")
      desWS.Range("V" & LastRow).Value = .Range("F5")
    Next brand
    
    LastRow = sreWS.Range("E" & .Rows.Count).End(xlUp).Row + 1
    sreWS.Range("A" & LastRow).Resize(, 1).Value = Array(.Range("D12"))
    sreWS.Range("B" & LastRow).Resize(, 2).Value = Array(.Range("O1"), .Range("N1"))
    sreWS.Range("D" & LastRow).Resize(, 3).Value = Array(.Range("F7"), .Range("J7"), .Range("J9"))
    sreWS.Range("G" & LastRow).Resize(, 7).Value = Array(.Range("L36"), .Range("L37"), .Range("L38"), .Range("I37"), .Range("I38"), Application.UserName, [Text(Now(), "DD-MM-YYYY HH:MM:SS")])
    sreWS.Range("N" & LastRow).Resize(, 1).Value = Array(.Range("H36"))
    sreWS.Range("O" & LastRow).Resize(, 1).Value = Array(.Range("J5"))
    sreWS.Range("P" & LastRow).Resize(, 1).Value = Array(.Range("F5"))
  End With
  Call ResetSalesReel
  Application.ScreenUpdating = True
End Sub

Sub ResetSalesReel()
  Dim scrsWS As Worksheet
  Set scrsWS = Sheets("Sales Reel")
  With scrsWS
    .Range("F5,F7,F9,J7,J9").Interior.Color = xlNone
    .Range("F5,F7,F9,J7,J9").Value = ""
    .Range("D12:K35").Interior.Color = xlNone
    .Range("D12:K35").Value = ""
    .Range("H36,I37,I38,L37").Interior.Color = xlNone
    .Range("H36,I37,I38,L37").Value = ""
  End With
End Sub
 
Upvote 0
Thanks, AP & AR are perfect, but in the Database, the cartage figure is appearing with each line of Brand which is required only 1 time in column N.
 
Upvote 0
the cartage figure is appearing with each line of Brand which is required only 1 time in column N
Sorry for that, I hadn't understood ?

I give you the updated code:
VBA Code:
'Purchase Module
Sub SaveNewDataPurchaseReel()
  Application.ScreenUpdating = True
  Dim LastRow As Long, brand As Range
  Dim abcWS As Worksheet, srcWS As Worksheet, desWS As Worksheet
  Dim cartage As Boolean
  
  Set srcWS = Sheets("Purchase Reel")
  Set desWS = Sheets("Database")
  Set abcWS = Sheets("AP")
  cartage = True
  With srcWS
    For Each brand In .Range("E12", .Range("E" & .Rows.Count).End(xlUp))
      LastRow = desWS.Range("E" & .Rows.Count).End(xlUp).Row + 1
      desWS.Range("A" & LastRow).Resize(, 1).Value = Array(.Range("D12"))
      desWS.Range("B" & LastRow).Resize(, 2).Value = Array(.Range("O1"), .Range("N1"))
      desWS.Range("D" & LastRow).Resize(, 3).Value = Array(.Range("F7"), .Range("J7"), .Range("J9"))
      desWS.Range("G" & LastRow).Value = .Range("E" & brand.Row)
      desWS.Range("H" & LastRow).Resize(, 6).Value = .Range("G" & brand.Row).Resize(, 6).Value
      If cartage Then
        desWS.Range("N" & LastRow).Resize(, 5).Value = Array(.Range("L37"), .Range("I37"), .Range("I38"), Application.UserName, [Text(Now(), "DD-MM-YYYY HH:MM:SS")])
      Else
        desWS.Range("O" & LastRow).Resize(, 4).Value = Array(.Range("I37"), .Range("I38"), Application.UserName, [Text(Now(), "DD-MM-YYYY HH:MM:SS")])
      End If
      cartage = False
      desWS.Range("S" & LastRow).Resize(, 1).Value = Array(.Range("F9"))
      desWS.Range("T" & LastRow).Resize(, 1).Value = Array(.Range("H36"))
      desWS.Range("U" & LastRow).Resize(, 1).Value = Array(.Range("J5"))
      desWS.Range("V" & LastRow).Resize(, 1).Value = Array(.Range("F5"))
    Next brand
  
    LastRow = abcWS.Range("E" & .Rows.Count).End(xlUp).Row + 1
    abcWS.Range("A" & LastRow).Resize(, 1).Value = Array(.Range("D12"))
    abcWS.Range("B" & LastRow).Resize(, 2).Value = Array(.Range("O1"), .Range("N1"))
    abcWS.Range("D" & LastRow).Resize(, 3).Value = Array(.Range("F7"), .Range("J7"), .Range("J9"))
    abcWS.Range("G" & LastRow).Resize(, 7).Value = Array(.Range("L36"), .Range("L37"), .Range("L38"), .Range("I37"), .Range("I38"), Application.UserName, [Text(Now(), "DD-MM-YYYY HH:MM:SS")])
    abcWS.Range("N" & LastRow).Resize(, 1).Value = Array(.Range("H36"))
    abcWS.Range("O" & LastRow).Resize(, 1).Value = Array(.Range("J5"))
    abcWS.Range("P" & LastRow).Resize(, 1).Value = Array(.Range("F5"))
  End With
  Call ResetPurchaseReel
  Application.ScreenUpdating = True
End Sub

Sub ResetPurchaseReel()
  Dim srcWS As Worksheet
  Set srcWS = Sheets("Purchase Reel")
  With srcWS
    .Range("F5,F7,F9,J7,J9").Interior.Color = xlNone
    .Range("F5,F7,F9,J7,J9").Value = ""
    .Range("D12:K35").Interior.Color = xlNone
    .Range("D12:K35").Value = ""
    .Range("I37:I38,L37,H36").Interior.Color = xlNone
    .Range("I37:I38,L37,H36").Value = ""
  End With
End Sub

'Sales Module
Sub SaveNewDataSalesReel()
  Application.ScreenUpdating = False
  Dim sreWS As Worksheet, scrsWS As Worksheet, desWS As Worksheet
  Dim LastRow As Long, brand As Range
  Dim cartage As Boolean
  
  Set scrsWS = Sheets("Sales Reel")
  Set desWS = Sheets("Database")
  Set sreWS = Sheets("AR")
  cartage = True
  With scrsWS
    For Each brand In .Range("E12", .Range("E" & .Rows.Count).End(xlUp))
      LastRow = desWS.Range("E" & .Rows.Count).End(xlUp).Row + 1
      desWS.Range("A" & LastRow).Resize(, 1).Value = Array(.Range("D12"))
      desWS.Range("B" & LastRow).Resize(, 2).Value = Array(.Range("O1"), .Range("N1"))
      desWS.Range("D" & LastRow).Resize(, 3).Value = Array(.Range("F7"), .Range("J7"), .Range("J9"))
      desWS.Range("G" & LastRow).Value = .Range("E" & brand.Row)
      desWS.Range("H" & LastRow).Resize(, 6).Value = .Range("G" & brand.Row).Resize(, 6).Value
      If cartage Then
        desWS.Range("N" & LastRow).Resize(, 5).Value = Array(.Range("L37"), .Range("I37"), .Range("I38"), Application.UserName, [Text(Now(), "DD-MM-YYYY HH:MM:SS")])
      Else
        desWS.Range("O" & LastRow).Resize(, 4).Value = Array(.Range("I37"), .Range("I38"), Application.UserName, [Text(Now(), "DD-MM-YYYY HH:MM:SS")])
      End If
      cartage = False
      desWS.Range("S" & LastRow).Value = .Range("F9")
      desWS.Range("T" & LastRow).Value = .Range("H36")
      desWS.Range("U" & LastRow).Value = .Range("J5")
      desWS.Range("V" & LastRow).Value = .Range("F5")
    Next brand
    
    LastRow = sreWS.Range("E" & .Rows.Count).End(xlUp).Row + 1
    sreWS.Range("A" & LastRow).Resize(, 1).Value = Array(.Range("D12"))
    sreWS.Range("B" & LastRow).Resize(, 2).Value = Array(.Range("O1"), .Range("N1"))
    sreWS.Range("D" & LastRow).Resize(, 3).Value = Array(.Range("F7"), .Range("J7"), .Range("J9"))
    sreWS.Range("G" & LastRow).Resize(, 7).Value = Array(.Range("L36"), .Range("L37"), .Range("L38"), .Range("I37"), .Range("I38"), Application.UserName, [Text(Now(), "DD-MM-YYYY HH:MM:SS")])
    sreWS.Range("N" & LastRow).Resize(, 1).Value = Array(.Range("H36"))
    sreWS.Range("O" & LastRow).Resize(, 1).Value = Array(.Range("J5"))
    sreWS.Range("P" & LastRow).Resize(, 1).Value = Array(.Range("F5"))
  End With
  Call ResetSalesReel
  Application.ScreenUpdating = True
End Sub

Sub ResetSalesReel()
  Dim scrsWS As Worksheet
  Set scrsWS = Sheets("Sales Reel")
  With scrsWS
    .Range("F5,F7,F9,J7,J9").Interior.Color = xlNone
    .Range("F5,F7,F9,J7,J9").Value = ""
    .Range("D12:K35").Interior.Color = xlNone
    .Range("D12:K35").Value = ""
    .Range("H36,I37,I38,L37").Interior.Color = xlNone
    .Range("H36,I37,I38,L37").Value = ""
  End With
End Sub
 
Upvote 0
Solution
Excellent DanteAmor - It's perfectly working as I needed, Many thanks.
Sorry for that, I hadn't understood ?

I give you the updated code:
VBA Code:
'Purchase Module
Sub SaveNewDataPurchaseReel()
  Application.ScreenUpdating = True
  Dim LastRow As Long, brand As Range
  Dim abcWS As Worksheet, srcWS As Worksheet, desWS As Worksheet
  Dim cartage As Boolean
 
  Set srcWS = Sheets("Purchase Reel")
  Set desWS = Sheets("Database")
  Set abcWS = Sheets("AP")
  cartage = True
  With srcWS
    For Each brand In .Range("E12", .Range("E" & .Rows.Count).End(xlUp))
      LastRow = desWS.Range("E" & .Rows.Count).End(xlUp).Row + 1
      desWS.Range("A" & LastRow).Resize(, 1).Value = Array(.Range("D12"))
      desWS.Range("B" & LastRow).Resize(, 2).Value = Array(.Range("O1"), .Range("N1"))
      desWS.Range("D" & LastRow).Resize(, 3).Value = Array(.Range("F7"), .Range("J7"), .Range("J9"))
      desWS.Range("G" & LastRow).Value = .Range("E" & brand.Row)
      desWS.Range("H" & LastRow).Resize(, 6).Value = .Range("G" & brand.Row).Resize(, 6).Value
      If cartage Then
        desWS.Range("N" & LastRow).Resize(, 5).Value = Array(.Range("L37"), .Range("I37"), .Range("I38"), Application.UserName, [Text(Now(), "DD-MM-YYYY HH:MM:SS")])
      Else
        desWS.Range("O" & LastRow).Resize(, 4).Value = Array(.Range("I37"), .Range("I38"), Application.UserName, [Text(Now(), "DD-MM-YYYY HH:MM:SS")])
      End If
      cartage = False
      desWS.Range("S" & LastRow).Resize(, 1).Value = Array(.Range("F9"))
      desWS.Range("T" & LastRow).Resize(, 1).Value = Array(.Range("H36"))
      desWS.Range("U" & LastRow).Resize(, 1).Value = Array(.Range("J5"))
      desWS.Range("V" & LastRow).Resize(, 1).Value = Array(.Range("F5"))
    Next brand
 
    LastRow = abcWS.Range("E" & .Rows.Count).End(xlUp).Row + 1
    abcWS.Range("A" & LastRow).Resize(, 1).Value = Array(.Range("D12"))
    abcWS.Range("B" & LastRow).Resize(, 2).Value = Array(.Range("O1"), .Range("N1"))
    abcWS.Range("D" & LastRow).Resize(, 3).Value = Array(.Range("F7"), .Range("J7"), .Range("J9"))
    abcWS.Range("G" & LastRow).Resize(, 7).Value = Array(.Range("L36"), .Range("L37"), .Range("L38"), .Range("I37"), .Range("I38"), Application.UserName, [Text(Now(), "DD-MM-YYYY HH:MM:SS")])
    abcWS.Range("N" & LastRow).Resize(, 1).Value = Array(.Range("H36"))
    abcWS.Range("O" & LastRow).Resize(, 1).Value = Array(.Range("J5"))
    abcWS.Range("P" & LastRow).Resize(, 1).Value = Array(.Range("F5"))
  End With
  Call ResetPurchaseReel
  Application.ScreenUpdating = True
End Sub

Sub ResetPurchaseReel()
  Dim srcWS As Worksheet
  Set srcWS = Sheets("Purchase Reel")
  With srcWS
    .Range("F5,F7,F9,J7,J9").Interior.Color = xlNone
    .Range("F5,F7,F9,J7,J9").Value = ""
    .Range("D12:K35").Interior.Color = xlNone
    .Range("D12:K35").Value = ""
    .Range("I37:I38,L37,H36").Interior.Color = xlNone
    .Range("I37:I38,L37,H36").Value = ""
  End With
End Sub

'Sales Module
Sub SaveNewDataSalesReel()
  Application.ScreenUpdating = False
  Dim sreWS As Worksheet, scrsWS As Worksheet, desWS As Worksheet
  Dim LastRow As Long, brand As Range
  Dim cartage As Boolean
 
  Set scrsWS = Sheets("Sales Reel")
  Set desWS = Sheets("Database")
  Set sreWS = Sheets("AR")
  cartage = True
  With scrsWS
    For Each brand In .Range("E12", .Range("E" & .Rows.Count).End(xlUp))
      LastRow = desWS.Range("E" & .Rows.Count).End(xlUp).Row + 1
      desWS.Range("A" & LastRow).Resize(, 1).Value = Array(.Range("D12"))
      desWS.Range("B" & LastRow).Resize(, 2).Value = Array(.Range("O1"), .Range("N1"))
      desWS.Range("D" & LastRow).Resize(, 3).Value = Array(.Range("F7"), .Range("J7"), .Range("J9"))
      desWS.Range("G" & LastRow).Value = .Range("E" & brand.Row)
      desWS.Range("H" & LastRow).Resize(, 6).Value = .Range("G" & brand.Row).Resize(, 6).Value
      If cartage Then
        desWS.Range("N" & LastRow).Resize(, 5).Value = Array(.Range("L37"), .Range("I37"), .Range("I38"), Application.UserName, [Text(Now(), "DD-MM-YYYY HH:MM:SS")])
      Else
        desWS.Range("O" & LastRow).Resize(, 4).Value = Array(.Range("I37"), .Range("I38"), Application.UserName, [Text(Now(), "DD-MM-YYYY HH:MM:SS")])
      End If
      cartage = False
      desWS.Range("S" & LastRow).Value = .Range("F9")
      desWS.Range("T" & LastRow).Value = .Range("H36")
      desWS.Range("U" & LastRow).Value = .Range("J5")
      desWS.Range("V" & LastRow).Value = .Range("F5")
    Next brand
   
    LastRow = sreWS.Range("E" & .Rows.Count).End(xlUp).Row + 1
    sreWS.Range("A" & LastRow).Resize(, 1).Value = Array(.Range("D12"))
    sreWS.Range("B" & LastRow).Resize(, 2).Value = Array(.Range("O1"), .Range("N1"))
    sreWS.Range("D" & LastRow).Resize(, 3).Value = Array(.Range("F7"), .Range("J7"), .Range("J9"))
    sreWS.Range("G" & LastRow).Resize(, 7).Value = Array(.Range("L36"), .Range("L37"), .Range("L38"), .Range("I37"), .Range("I38"), Application.UserName, [Text(Now(), "DD-MM-YYYY HH:MM:SS")])
    sreWS.Range("N" & LastRow).Resize(, 1).Value = Array(.Range("H36"))
    sreWS.Range("O" & LastRow).Resize(, 1).Value = Array(.Range("J5"))
    sreWS.Range("P" & LastRow).Resize(, 1).Value = Array(.Range("F5"))
  End With
  Call ResetSalesReel
  Application.ScreenUpdating = True
End Sub

Sub ResetSalesReel()
  Dim scrsWS As Worksheet
  Set scrsWS = Sheets("Sales Reel")
  With scrsWS
    .Range("F5,F7,F9,J7,J9").Interior.Color = xlNone
    .Range("F5,F7,F9,J7,J9").Value = ""
    .Range("D12:K35").Interior.Color = xlNone
    .Range("D12:K35").Value = ""
    .Range("H36,I37,I38,L37").Interior.Color = xlNone
    .Range("H36,I37,I38,L37").Value = ""
  End With
End Sub
 
Upvote 0
Im glad to help you, thanks for the feedback.
Hi DanteAmor,

Another little change is required as follows, please.

While performing sales entry the quantity & amount should appear as negative in the database column K & M.

Many thanks in advance.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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