Data movement in 2 sheets

Zubair

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

How can I move Purchase data in 2 sheets i.e. Datawarehouse and AP ?



Purchase entry tab
Mr. Excel.xlsx
ABCDE
1Document No.20003
2Date4/3/2022
3Supplier No.ProductQtyRateAmount
458F42100858,500
558F90105818,505
658F991258911,125
7
8
9
10Subtotal28,130
11Cartage500
12Grand Total28,630
Purchase
Cell Formulas
RangeFormula
E4:E6E4=+C4*D4
E10E10=SUM(E4:E9)
E12E12=+E10+E11



Data warehouse tab - All information
Mr. Excel.xlsx
ABCDEFGHI
1Document No.DateSupplier No.ProductQtyRate Amount Cartage Grand Total
2200014/2/202221F4250653,25020010,913
321F9051693,519
421F9958683,944
5200024/3/202240F433003510,5005,00044,380
640F503703814,060
740F683803914,820
8200034/3/202258F42100858,50050028,630
958F90105818,505
1058F991258911,125
Data warehouse
Cell Formulas
RangeFormula
G5:G7G5=+E5*F5


Accounts Payable tab (AP) - selected information with a negative sign
Mr. Excel.xlsx
ABCDEF
1Document No.DateSupplier No.SubtotalCartageGrand Total
2200014/2/202221(10,713)(200)(10,913)
3200024/3/202240(39,380)(5,000)(44,380)
4200034/3/202258(28,130)(500)(28,630)
AP
Cell Formulas
RangeFormula
F2:F4F2=+D2+E2


after data transfer input data to clear.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Let me check what you need:
Once the purchase sheet is filled out, you want a macro to :
  • transfer the information from 'Purchase' to 'Data Warehouse'
  • and the information and costs (as negative) to 'Accounts Payable'
correct?
 
Upvote 0
Let me check what you need:
Once the purchase sheet is filled out, you want a macro to :
  • transfer the information from 'Purchase' to 'Data Warehouse'
  • and the information and costs (as negative) to 'Accounts Payable'
correct?
correct
 
Upvote 0
VBA Code:
Option Explicit

Sub PurchaseTransfer()
    Dim vIn As Variant, vWH As Variant, vAP As Variant, vCost As Variant
    Dim lRi As Long, lCi As Long, lRw As Long, lRa As Long, lItems As Long, UB As Long
    
    'get entry data into arrays for fast processing
    vIn = Sheets("Purchase").Range("A3").CurrentRegion
    UB = UBound(vIn, 1)
    
    vCost = Sheets("Purchase").Range("A:A").Find("Subtotal").Offset(0, 4).Resize(3, 1)
        
    lItems = UB - 3
    
    'resize output arrays
    ReDim vWH(1 To lItems, 1 To 9)
    ReDim vAP(1 To 1, 1 To 6)
    
    'fill out warehouse array
    vWH(1, 1) = vIn(1, 5) 'Doc No
    vWH(1, 2) = vIn(2, 5) 'Date
    vWH(1, 8) = vCost(2, 1) 'Cartage
    vWH(1, 9) = vCost(3, 1) 'Grand Tot
    
    For lRi = 4 To UB
        lRw = lRw + 1
        For lCi = 1 To 5
            vWH(lRw, lCi + 2) = vIn(lRi, lCi)
        Next lCi
    Next lRi
    
    'fill out Accounts Payable array
    vAP(1, 1) = vIn(1, 5) 'Doc No
    vAP(1, 2) = vIn(2, 5) 'Date
    vAP(1, 3) = vIn(4, 1) 'Suppl No
    vAP(1, 4) = -vCost(1, 1) 'Subtot
    vAP(1, 5) = -vCost(2, 1) 'Cart
    vAP(1, 6) = -vCost(3, 1) 'Grndtot
    
    'Write arrays to sheets
    With Sheets("Data Warehouse")
        lRw = .Range("A1").CurrentRegion.Rows.Count
        .Range("A" & lRw + 1).Resize(lItems, 9) = vWH
    End With
    With Sheets("AP")
        lRa = .Range("A1").CurrentRegion.Rows.Count
        .Range("A" & lRa + 1).Resize(1, 6) = vAP
    End With
End Sub
 
Upvote 0
VBA Code:
Option Explicit

Sub PurchaseTransfer()
    Dim vIn As Variant, vWH As Variant, vAP As Variant, vCost As Variant
    Dim lRi As Long, lCi As Long, lRw As Long, lRa As Long, lItems As Long, UB As Long
   
    'get entry data into arrays for fast processing
    vIn = Sheets("Purchase").Range("A3").CurrentRegion
    UB = UBound(vIn, 1)
   
    vCost = Sheets("Purchase").Range("A:A").Find("Subtotal").Offset(0, 4).Resize(3, 1)
       
    lItems = UB - 3
   
    'resize output arrays
    ReDim vWH(1 To lItems, 1 To 9)
    ReDim vAP(1 To 1, 1 To 6)
   
    'fill out warehouse array
    vWH(1, 1) = vIn(1, 5) 'Doc No
    vWH(1, 2) = vIn(2, 5) 'Date
    vWH(1, 8) = vCost(2, 1) 'Cartage
    vWH(1, 9) = vCost(3, 1) 'Grand Tot
   
    For lRi = 4 To UB
        lRw = lRw + 1
        For lCi = 1 To 5
            vWH(lRw, lCi + 2) = vIn(lRi, lCi)
        Next lCi
    Next lRi
   
    'fill out Accounts Payable array
    vAP(1, 1) = vIn(1, 5) 'Doc No
    vAP(1, 2) = vIn(2, 5) 'Date
    vAP(1, 3) = vIn(4, 1) 'Suppl No
    vAP(1, 4) = -vCost(1, 1) 'Subtot
    vAP(1, 5) = -vCost(2, 1) 'Cart
    vAP(1, 6) = -vCost(3, 1) 'Grndtot
   
    'Write arrays to sheets
    With Sheets("Data Warehouse")
        lRw = .Range("A1").CurrentRegion.Rows.Count
        .Range("A" & lRw + 1).Resize(lItems, 9) = vWH
    End With
    With Sheets("AP")
        lRa = .Range("A1").CurrentRegion.Rows.Count
        .Range("A" & lRa + 1).Resize(1, 6) = vAP
    End With
End Sub
Marvelous!

Working perfectly,

But heading Subtotal, Cartage & Grand Total are also moving in the tab "Date Warehouse" which is not required, hope you will make necessary changes, also please add code to clear entry in Purchase tab after running the macro.

AP & GL transfer.xlsx
ABCDEF
1Document No.20004
2Date15/03/2022
3Supplier No.ProductQtyRateAmount
41007Nazeer25010526,250
51007Box Board26010627,560
61007Dubai27010728,890
71007Liner28010830,240
81007Fluting29010931,610
91007Special30010631,800
10Subtotal176,350
11Cartage51,551
12Grand Total227,901
13
Purchase
Cell Formulas
RangeFormula
E4:E9E4=+C4*D4
E10E10=SUM(E4:E9)
E12E12=+E10+E11


AP & GL transfer.xlsx
ABCDEFGHIJ
1Document No.DateSupplier No.ProductQtyRate Amount Cartage Grand Total
2200014/2/202221F4250653,25020010,913
321F9051693,519
421F9958683,944
5200024/3/202240F433003510,5005,00044,380
640F503703814,060
740F683803914,820
8200034/3/202258F42100858,50050028,630
958F90105818,505
1058F991258911,125
11200034/3/202258F42100858,50050028,630
1258F90105818,505
1358F991258911,125
142000415/03/20221005Craft15022537,55051,551202,206
151005Ultra15553249,760
161005Special15454163,345
172000415/03/20221007Nazeer25010526,25051,551227,901
181007Box Board26010627,560
191007Dubai27010728,890
201007Liner28010830,240
211007Fluting29010931,610
221007Special30010631,800
23Subtotal176,350
24Cartage51,551
25Grand Total227,901
26
27
Data warehouse
Cell Formulas
RangeFormula
G5:G7G5=+E5*F5
 
Upvote 0
Hi, post the layout how it should be after clearing …​
AP & GL transfer.xlsm
ABCDE
1Document No.
2Date
3Supplier No.ProductQtyRateAmount
4
5
6
7
8
9
10Subtotal-
11Cartage
12Grand Total-
Purchase
Cell Formulas
RangeFormula
E10E10=SUM(E4:E9)
E12E12=+E10+E11
 
Upvote 0
Hi Zubair, the following code will clear the entry form.

I don't understand your comment about not putting cartage and grand total on the warehouse sheet, as your example shows it there.
If you don't want it then comment out two lines. I have given the instructions in the code: there are two comments with <<<<<<
Read and act on those comments.
VBA Code:
Option Explicit

Sub PurchaseTransfer()
    Dim vIn As Variant, vWH As Variant, vAP As Variant, vCost As Variant
    Dim lRi As Long, lCi As Long, lRw As Long, lRa As Long, lItems As Long, UB As Long
    
    'get entry data into arrays for fast processing
    vIn = Sheets("Purchase").Range("A3").CurrentRegion
    UB = UBound(vIn, 1)
    
    vCost = Sheets("Purchase").Range("A:A").Find("Subtotal").Offset(0, 4).Resize(3, 1)
        
    lItems = UB - 3
    
    'resize output arrays
    ReDim vWH(1 To lItems, 1 To 9)
    ReDim vAP(1 To 1, 1 To 6)
    
    'fill out warehouse array
    vWH(1, 1) = vIn(1, 5) 'Doc No
    vWH(1, 2) = vIn(2, 5) 'Date
    vWH(1, 8) = vCost(2, 1) 'Cartage        <<<<<< Put a ' in front of this line to disable Cartage being printed on the Warehouse sheet
    vWH(1, 9) = vCost(3, 1) 'Grand Tot      <<<<<< Put a ' in front of this line to disable Grand Total being printed on the Warehouse sheet
    
    For lRi = 4 To UB
        lRw = lRw + 1
        For lCi = 1 To 5
            vWH(lRw, lCi + 2) = vIn(lRi, lCi)
        Next lCi
    Next lRi
    
    'fill out Accounts Payable array
    vAP(1, 1) = vIn(1, 5) 'Doc No
    vAP(1, 2) = vIn(2, 5) 'Date
    vAP(1, 3) = vIn(4, 1) 'Suppl No
    vAP(1, 4) = -vCost(1, 1) 'Subtot
    vAP(1, 5) = -vCost(2, 1) 'Cart
    vAP(1, 6) = -vCost(3, 1) 'Grndtot
    
    'Write arrays to sheets
    With Sheets("Data Warehouse")
        lRw = .Range("A1").CurrentRegion.Rows.Count
        .Range("A" & lRw + 1).Resize(lItems, 9) = vWH
    End With
    With Sheets("AP")
        lRa = .Range("A1").CurrentRegion.Rows.Count
        .Range("A" & lRa + 1).Resize(1, 6) = vAP
    End With
    
    'clear input data
    With Sheets("Purchase")
        .Range("A4").Resize(lItems, 5).ClearContents
        .Range("E1:E2").ClearContents
    End With
End Sub
 
Upvote 0
Hi Zubair, the following code will clear the entry form.

I don't understand your comment about not putting cartage and grand total on the warehouse sheet, as your example shows it there.
If you don't want it then comment out two lines. I have given the instructions in the code: there are two comments with <<<<<<
Read and act on those comments.
VBA Code:
Option Explicit

Sub PurchaseTransfer()
    Dim vIn As Variant, vWH As Variant, vAP As Variant, vCost As Variant
    Dim lRi As Long, lCi As Long, lRw As Long, lRa As Long, lItems As Long, UB As Long
   
    'get entry data into arrays for fast processing
    vIn = Sheets("Purchase").Range("A3").CurrentRegion
    UB = UBound(vIn, 1)
   
    vCost = Sheets("Purchase").Range("A:A").Find("Subtotal").Offset(0, 4).Resize(3, 1)
       
    lItems = UB - 3
   
    'resize output arrays
    ReDim vWH(1 To lItems, 1 To 9)
    ReDim vAP(1 To 1, 1 To 6)
   
    'fill out warehouse array
    vWH(1, 1) = vIn(1, 5) 'Doc No
    vWH(1, 2) = vIn(2, 5) 'Date
    vWH(1, 8) = vCost(2, 1) 'Cartage        <<<<<< Put a ' in front of this line to disable Cartage being printed on the Warehouse sheet
    vWH(1, 9) = vCost(3, 1) 'Grand Tot      <<<<<< Put a ' in front of this line to disable Grand Total being printed on the Warehouse sheet
   
    For lRi = 4 To UB
        lRw = lRw + 1
        For lCi = 1 To 5
            vWH(lRw, lCi + 2) = vIn(lRi, lCi)
        Next lCi
    Next lRi
   
    'fill out Accounts Payable array
    vAP(1, 1) = vIn(1, 5) 'Doc No
    vAP(1, 2) = vIn(2, 5) 'Date
    vAP(1, 3) = vIn(4, 1) 'Suppl No
    vAP(1, 4) = -vCost(1, 1) 'Subtot
    vAP(1, 5) = -vCost(2, 1) 'Cart
    vAP(1, 6) = -vCost(3, 1) 'Grndtot
   
    'Write arrays to sheets
    With Sheets("Data Warehouse")
        lRw = .Range("A1").CurrentRegion.Rows.Count
        .Range("A" & lRw + 1).Resize(lItems, 9) = vWH
    End With
    With Sheets("AP")
        lRa = .Range("A1").CurrentRegion.Rows.Count
        .Range("A" & lRa + 1).Resize(1, 6) = vAP
    End With
   
    'clear input data
    With Sheets("Purchase")
        .Range("A4").Resize(lItems, 5).ClearContents
        .Range("E1:E2").ClearContents
    End With
End Sub
I mean Text in tab "Purchase" cell A10:A12 also moving in a tab Data warehouse, I have clear all old data and put fresh data in purchase and run macro its giving as follows:


Before running Macro
AP & GL transfer.xlsm
ABCDE
1Document No.1000
2Date1/2/2000
3Supplier No.ProductQtyRateAmount
420Japan122101,220
530China150152,250
640Sudan145557,975
750UK85151,275
860USA155152,325
970UAE159518,109
10Subtotal23,154
11Cartage500
12Grand Total23,654
Purchase
Cell Formulas
RangeFormula
E4:E9E4=+C4*D4
E10E10=SUM(E4:E9)
E12E12=+E10+E11


After macro
AP & GL transfer.xlsm
ABCDEFGHI
1Document No.DateSupplier No.ProductQtyRate Amount Cartage Grand Total
210001/2/200020Japan122101,22050023,654
330China150152,250
440Sudan145557,975
550UK85151,275
660USA155152,325
770UAE159518,109
8Subtotal23,154
9Cartage500
10Grand Total23,654
Data warehouse


C8:G10 not required.

AP tab is ok.

After running tab the input data is cleared but also clearing A10:A12 as appearing in picture.

AP & GL transfer.xlsm
ABCDE
1Document No.
2Date
3Supplier No.ProductQtyRateAmount
4
5
6
7
8
9
10
11
12
Purchase
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,237
Members
452,898
Latest member
Capolavoro009

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