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

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hi and welcome to MrExcel.

i want to make copy and paste some specific cells from invoices to summery sheet
You mean summary sheet.

Check if this works for you. I did some enhancement to concatenate the results. If they don't work for you, I can delete them.

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
            cad = cad & sh.Cells(i, j) & "|"
          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
 
Last edited:
Upvote 0
Hi and welcome to MrExcel.


You mean summary sheet.

Check if this works for you. I did some enhancement to concatenate the results. If they don't work for you, I can delete them.

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
            cad = cad & sh.Cells(i, j) & "|"
          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
Dear DanteAm,

thanks for the quick reply and code, i have corrected as 'summary", unfortunately its not working with me.

when i run the code not getting any error message, but data not reflecting to the summary sheet

 
Upvote 0
Do you have a "sheet" in the same book where you have the "summary" sheet?
 
Upvote 0
Do you have a "sheet" in the same book where you have the "summary" sheet?
Dear DanteAmor,

Yes, these are all sheets in one workbook, four invoice sheet & one summary sheet

i can write exact cell range;
Copy from Invoice sheet and paste to summary sheet

B2 to B2
A5:B8 to C2
G5:K10 to G2
C12 to E2
B20:C29,F20:G29,J20:K29 to D2
L30 to F2

thank you so much
 
Upvote 0
Dear DanteAmor,

Perfectly working your file, THANK YOU SO MUCH FOR YOUR TIME AND HELP.

I have added one more sheet as sometimes invoices more or less, now perfectly showing all sheets details on the summary sheet.

Just only one thing, two more columns extra copied from invoice sheet which is not required (Value & S.N) eg:- FOOD|3|10|11||||21|||

Appreciated, thanks & Regards,
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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