VBA Code for Automatic Summary/Report

Annasksd

New Member
Joined
Jun 6, 2021
Messages
12
Office Version
  1. 2013
Platform
  1. Windows
Hello Everyone,

Good Day !

I'm learning about excel vba coding and i have an excel file which is something like small invoices sheets and i have added one more sheet like summery/report.

Only i want to make copy and paste some specific cells from invoices to summery sheet, attached small sheet also highlighted for the reference.

sometimes invoices will be more or less , so i have to do for loop

please help anyone to get vba code

TEST INVOICE.xlsm
ABCDEFGHIJKL
1INVOICE NOORIGINDESTINATIONDATE
22510DXBINDIA01-06-2021
3SENDER ID2855050550
4SHIPPER / SENDER'S NAME & ADDRESSCONSIGNEE / RECEIVER'S NAME & ADDRESS
5JOSE LUISASHOK
6MANGAFTHRAMMAL HOUSE
7DXBVADANAPPALLY
8ID #2855050550CALICUT DT
9KERALAPINCODE670106
10PHONE NO:9895995880
11DETAILS OF SHIPEMENTFREIGHT CHARGES (KWD)I, the undersigned on behalf of the above sender/shipper acknowledge the receipt of the goods in good condition.
12Total Weight (KG)23.500PRE PAID
13No. of Pcs1.00Receiver's Name:
14ShipmentEXPRESS COURIERDate:Time:
15Description of ContentGiftSignature:
16INVOICE / PACKING LISTBOX NUMBER2510
17SHIPPERSame As AboveCONSIGNEESame As Above
18DESCRIPTION OF GOODS
19S.NITEMSQTYVALUE($)S.NITEMSQTYVALUE($)S.NITEMSQTYVALUE($)
201FOOD1010.0011FOOD1010.0011FOOD1010.00
212STATIONARY115.0012STATIONARY115.0012STATIONARY115.00
223CLOTH 616.0013CLOTH 616.0013CLOTH 616.00
234HOUSE HOLD36.0014HOUSE HOLD36.0014HOUSE HOLD36.00
245BOOKS24.0015BOOKS24.0015BOOKS24.00
256FOOD1010.0016FOOD1010.0016FOOD1010.00
267STATIONARY115.0017STATIONARY115.0017STATIONARY115.00
278CLOTH 616.0018CLOTH 616.0018CLOTH 616.00
289HOUSE HOLD36.0019HOUSE HOLD36.0019HOUSE HOLD36.00
2910BOOKS24.0020BOOKS24.0020BOOKS24.00
30NUMBER OF PIECES1TOTAL WEIGHT (KG)23.500TOTAL VALUE OF GOODS246.00
sheet
Cell Formulas
RangeFormula
B8B8=C3
J16J16=B2
G30G30=C12
L30L30=SUM(D20:D29,H20:H29,L20:L29)



TEST INVOICE.xlsm
ABCDEFG
1SNINOICE NOSENDERS ADDRESSGOODS WEIGHTVALUECONSIGNEE ADDRESS
212510JOSE LUISMANGAF2855050550FOOD 10 10.00 11 FOOD 10 10.00 11 FOOD 10 STATIONARY 11 5.00 12 STATIONARY 11 5.00 12 STATIONARY 11 CLOTH 6 16.00 13 CLOTH 6 16.00 13 CLOTH 6 HOUSE HOLD 3 6.00 14 HOUSE HOLD 3 6.00 14 HOUSE HOLD 3 BOOKS 2 4.00 15 BOOKS 2 4.00 15 BOOKS 2 FOOD 10 10.00 16 FOOD 10 10.00 16 FOOD 10 STATIONARY 11 5.00 17 STATIONARY 11 5.00 17 STATIONARY 11 CLOTH 6 16.00 18 CLOTH 6 16.00 18 CLOTH 6 HOUSE HOLD 3 6.00 19 HOUSE HOLD 3 6.00 19 HOUSE HOLD 3 BOOKS 2 4.00 20 BOOKS 2 4.00 20 BOOKS 2 23.500246.00ASHOKTHRAMMAL HOUSE VADANAPPALLYCALICUT DTKERALAPINCODE6701069895995880
32
43
54
Summery
Cell Formulas
RangeFormula
B2B2=sheet!B2
C2C2=sheet!A5&sheet!A6&sheet!B8
E2E2=sheet!C12
F2F2=sheet!L30
G2G2=sheet!G5&sheet!G6&sheet!G7&sheet!G8&sheet!G9&sheet!J9&sheet!K9&sheet!J10
 

Attachments

  • Capture1.JPG
    Capture1.JPG
    148.3 KB · Views: 24
Try this

VBA Code:
Sub SummaryReport()
  Dim sh As Worksheet, sumSh As Worksheet
  Dim i As Long, j As Long, lr As Long, n As Long
  Dim cad As String, c As Variant
    
  Set sumSh = Sheets("summary")
  For Each sh In Sheets
    Select Case LCase(sh.Name)
      Case LCase(sumSh.Name)
      Case Else
      
        lr = sumSh.Range("A" & Rows.Count).End(3).Row
        If lr = 1 Then n = 1 Else n = sumSh.Range("A" & lr).Value + 1
        lr = lr + 1
        
        sumSh.Range("A" & lr) = n
        sumSh.Range("B" & lr) = sh.Range("B2")
        sumSh.Range("C" & lr) = sh.Range("A5") & "|" & sh.Range("A6") & "|" & sh.Range("B8")
        
        cad = ""
        For i = 20 To 29
          For j = Columns("B").Column To Columns("L").Column
            Select Case j
              Case 2, 3, 6, 7, 10, 11
                cad = cad & sh.Cells(i, j) & "|"
            End Select
          Next j
          cad = Left(cad, Len(cad) - 1)
          cad = cad & Chr(10)
        Next i
        sumSh.Range("D" & lr) = Left(cad, Len(cad) - 1)
        
        sumSh.Range("E" & lr) = sh.Range("C12")
        sumSh.Range("F" & lr) = sh.Range("L30")
        
        cad = ""
        For Each c In Array("G5", "G6", "G7", "G8", "G9", "J9", "K9", "J10")
          cad = cad & sh.Range(c) & "|"
        Next
        sumSh.Range("G" & lr) = Left(cad, Len(cad) - 1)
        
    End Select
  Next

End Sub
 
Upvote 0
Solution

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,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

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