Hello all
First of all I need to say thank you to all of you that have helped me and write (tried and did) the below code.
The code is working perfectly. What the code do is that it collect data from 3 or more sheets and insert them to another sheet in order to create an invoice. So far , so good.
The problem is that there is an alert if the inserted data are more than row 70 to end sub. Now there is the need to incremental add rows to invoice and not checking if they are more than 70.
Starts from Row 15 add rows if there is a need. I have tried to make it happen using a tutorial from VBA Macro to Insert Row in Excel Based on Criteria (4 Methods) but no luck.
Also the row must have columns A B C D and D has a formula (B*C) .Can someone please help to make this work?
Here it the code
Thank you in advance!
First of all I need to say thank you to all of you that have helped me and write (tried and did) the below code.
The code is working perfectly. What the code do is that it collect data from 3 or more sheets and insert them to another sheet in order to create an invoice. So far , so good.
The problem is that there is an alert if the inserted data are more than row 70 to end sub. Now there is the need to incremental add rows to invoice and not checking if they are more than 70.
Starts from Row 15 add rows if there is a need. I have tried to make it happen using a tutorial from VBA Macro to Insert Row in Excel Based on Criteria (4 Methods) but no luck.
Also the row must have columns A B C D and D has a formula (B*C) .Can someone please help to make this work?
Here it the code
VBA Code:
Sub BuildInvoiceAll()
Dim ws As Variant, sht As Variant
Dim i As Long, lr As Long, nr As Long, c As Long
Dim cell As Range
Dim N$
Dim ws1 As String
Const sPw As String = "*****" ' <--- Lock code
For Each shtName In ThisWorkbook.Worksheets
shtName.Unprotect sPw
Next shtName
ws1 = ActiveSheet.Name
Application.ScreenUpdating = False
' Set array of worksheet names to copy from
ws = Array("1.Power Distribution - Dimmer", "2.POWER CABLES - ADAPTORS", "3.CABLES (OTHER) - CABLE CROSS")
' Array of columns to check
sht = Array("D")
nr = 15
Sheets("PROFORMA DRYHIRE").Range("A15:C70").ClearContents
' Loop through all sheets in sheets array
For i = LBound(ws) To UBound(ws)
' Loop through all columns in the column array
For c = LBound(sht) To UBound(sht)
' Find last row in column with data
With Sheets(ws(i))
lr = .Cells(Rows.Count, sht(c)).End(xlUp).Row
' Loop through all cells in column
For Each cell In .Range(.Cells(1, sht(c)), .Cells(lr, sht(c)))
' Check to see if value is numeric and not 0
If (IsNumeric(cell.Value)) And (cell.Value <> 0) Then
' Copy cells C, D, E to columns A, B, C of main sheet
.Range(.Cells(cell.Row, "C"), .Cells(cell.Row, "E")).Copy
Sheets("PROFORMA DRYHIRE").Cells(nr, "A").PasteSpecial Paste:=xlPasteValues
' Increment nr counter
nr = nr + 1
' Check to see if rows are full
If nr > 70 Then
MsgBox "Rows are full"
Exit Sub
End If
End If
Next cell
End With
Next c
Next i
MsgBox "Done! Invoice created."
End Sub
EXAMPLE.xlsm | ||||||
---|---|---|---|---|---|---|
A | B | C | D | |||
1 | ||||||
2 | ΥΠΕΥΘΥΝΟΣ | |||||
3 | ΠΕΛΑΤΗΣ | |||||
4 | ΥΠΟΨΙΝ | |||||
5 | ΔΙΕΥΘΥΝΣΗ | |||||
6 | ΠΟΛΗ | |||||
7 | ΑΦΜ | |||||
8 | ΔOY | |||||
9 | ΤΗΛ | |||||
10 | ||||||
11 | ΠΑΡΑΓΩΓΗ | |||||
12 | ΠΕΡΙΟΔΟΣ | |||||
13 | ||||||
14 | ΤΥΠΟΣ - ΠΕΡΙΓΡΑΦΗ | ΤΕΜΑΧΙΑ | ΤΙΜΗ ΜΟΝΑΔΟΣ | ΣΥΝΟΛΟ | ||
15 | 0,00 € | |||||
16 | 0,00 € | |||||
17 | 0,00 € | |||||
18 | 0,00 € | |||||
19 | 0,00 € | |||||
20 | 0,00 € | |||||
21 | 0,00 € | |||||
22 | 0,00 € | |||||
23 | 0,00 € | |||||
24 | 0,00 € | |||||
25 | 0,00 € | |||||
26 | 0,00 € | |||||
27 | 0,00 € | |||||
28 | 0,00 € | |||||
29 | 0,00 € | |||||
30 | 0,00 € | |||||
31 | 0,00 € | |||||
32 | 0,00 € | |||||
33 | 0,00 € | |||||
34 | 0,00 € | |||||
35 | 0,00 € | |||||
36 | 0,00 € | |||||
37 | 0,00 € | |||||
38 | 0,00 € | |||||
39 | 0,00 € | |||||
40 | 0,00 € | |||||
41 | 0,00 € | |||||
42 | 0,00 € | |||||
43 | 0,00 € | |||||
44 | 0,00 € | |||||
45 | 0,00 € | |||||
46 | 0,00 € | |||||
47 | 0,00 € | |||||
48 | 0,00 € | |||||
49 | 0,00 € | |||||
50 | 0,00 € | |||||
51 | 0,00 € | |||||
52 | 0,00 € | |||||
53 | 0,00 € | |||||
54 | 0,00 € | |||||
55 | 0,00 € | |||||
56 | 0,00 € | |||||
57 | 0,00 € | |||||
58 | 0,00 € | |||||
59 | 0,00 € | |||||
60 | 0,00 € | |||||
61 | 0,00 € | |||||
62 | 0,00 € | |||||
63 | 0,00 € | |||||
64 | 0,00 € | |||||
65 | 0,00 € | |||||
66 | 0,00 € | |||||
67 | 0,00 € | |||||
68 | 0,00 € | |||||
69 | 0,00 € | |||||
70 | 0,00 € | |||||
71 | ΣΥΝΟΛΟ ΗΜΕΡΑΣ | 0,00 € | ||||
72 | ΧΡΕΩΣΕΙΣ | |||||
73 | ΣΥΝΟΛΟ | 0,00 € | ||||
74 | ΕΚΠΤΩΣΗ | 0,00 € | ||||
75 | ΦΠΑ | 0,00 € | ||||
76 | ΤΕΛΙΚΟ ΣΥΝΟΛΟ | 0,00 € | ||||
77 | ||||||
PROFORMA DRYHIRE |
Cell Formulas | ||
---|---|---|
Range | Formula | |
D15:D70 | D15 | =B15*C15 |
D71 | D71 | = SUM(D15:D70) |
D73 | D73 | =D72*D71 |
D74 | D74 | =D73*0.8 |
D75 | D75 | =D74*0.24 |
D76 | D76 | =D74+D75 |
EXAMPLE.xlsm | |||||||
---|---|---|---|---|---|---|---|
B | C | D | E | F | |||
2 | Power Distribution - Dimmer | ||||||
3 | Power Distribution Three Phase | ||||||
4 | Stock | Three Phase 400A | Book | Daily Rate | |||
5 | |||||||
6 | |||||||
7 | 1 | Power Distribution Rack Three Phase 400A -1 CEE | |||||
8 | |||||||
9 | |||||||
10 | Stock | Three Phase 125A Lighting - Truss | Book | Daily Rate | |||
11 | |||||||
12 | |||||||
13 | 2 | Power Distribution Box - Splitter Three Phase 125A Male / 1x125A 2x63A Female CEE | |||||
14 | 2 | Power Distribution Rack - Splitter Three Phase 125A Male / 1x125A 2x63A 1x32A Female CEE | |||||
15 | 6 | Power Distribution Rack Three Phase 125A CEE Type 1 | |||||
16 | 4 | Power Distribution Rack Three Phase 125A CEE Type 1 New | |||||
17 | 7 | Power Distribution Rack Three Phase 125A CEE Type 2 | |||||
18 | |||||||
19 | |||||||
20 | |||||||
21 | Stock | Three Phase 63A Lighting - Truss | Book | Daily Rate | |||
22 | |||||||
23 | |||||||
24 | 6 | Power Distribution Box Indu Three Phase 63A CEE | |||||
25 | 3 | Power Distribution Box Indu Three Phase 63A CEE (RCD) | |||||
26 | 4 | Power Distribution Box Indu Three Phase 63A CEE (RCD+Multimeter) | |||||
27 | 6 | Power Distribution Rack Three Phase 63A CEE Type 1 | |||||
28 | 4 | Power Distribution Rack Three Phase 63A CEE Type 1 New | |||||
29 | 6 | Power Distribution Rack Three Phase 63A Modular | |||||
30 | |||||||
31 | |||||||
32 | |||||||
33 | Stock | Three Phase 32A Lighting - Truss | Book | Daily Rate | |||
34 | |||||||
35 | |||||||
36 | 4 | Power Distribution Box Indu Three Phase 32 CEE (3 X 32A Mono) | |||||
37 | 34 | Power Distribution Box Indu Three Phase 32A CEE (6x16A) | |||||
38 | 3 | Power Distribution Box Indu Three Phase 32A CEE (6xSchuko) | |||||
39 | 2 | Power Distribution Box Indu Three Phase 32A CEE New (RCD+Multimeter) | |||||
40 | 4 | Power Distribution Rack 3U Three Phase 32A CEE | |||||
41 | 4 | Power Distribution Rack 3U Three Phase 32A CEE (6 x Twin Schuko) | |||||
42 | 5 | Power Distribution Rack 3U Three Phase 32A CEE (RCD) | |||||
43 | |||||||
44 | |||||||
45 | |||||||
46 | |||||||
47 | Stock | Three Phase 125A Audio | Book | Daily Rate | |||
48 | |||||||
49 | |||||||
50 | 4 | 125A CEE Type 1 S Three Phase Power Distribution Rack | |||||
51 | 1 | 125A CEE Type 2 S Three Phase Power Distribution Rack | |||||
52 | |||||||
53 | |||||||
54 | Stock | Three Phase 63A Audio | Book | Daily Rate | |||
55 | |||||||
56 | |||||||
57 | 4 | 63A CEE Type 1 S Three Phase Power Distribution Rack | |||||
58 | 2 | 63A CEE Type 2 S Three Phase Power Distribution Box Indu | |||||
59 | 2 | 63A CEE Type 3 S Three Phase Power Distribution Box Indu | |||||
60 | 3 | 63A CEE Type 4 S Three Phase Power Distribution Box Walther | |||||
61 | |||||||
62 | |||||||
63 | Stock | Three Phase 32A Audio | Book | Daily Rate | |||
64 | |||||||
65 | |||||||
66 | 4 | 32A CEE Type 1 S Three Phase Power Distribution Rack | |||||
67 | 6 | 32A CEE Type 2 S Three Phase Power Distribution Box Walther | |||||
68 | 4 | 32A CEE Type 3 S Three Phase Power Distribution Box Walther | |||||
69 | |||||||
70 | |||||||
71 | Dimmer | ||||||
72 | Stock | Dimmer Set | Book | Daily Rate | |||
73 | |||||||
74 | |||||||
75 | 5 | Elecrtron 2 x Actor 716 12 Ch. Rack Total 24Ch. x 3 Kw Set | |||||
76 | 2 | Elecrtron 2 x Actor 716 12 Ch + 2 x Actor 616 6 Ch. Rack Total 36Ch. x 3 Kw Set (Blue) | |||||
77 | 3 | Elecrtron 3 x Actor 716 12 Ch. Rack Total 36Ch. x 3 Kw Set (Black) Set | |||||
78 | 2 | MA Lighting Digital Dimmer 2 x 12 x 3,7 Kw + MA Lighting Power Distributor 125A Red In / 2x63A Red - 1 x Schuko Set Out | |||||
79 | 1 | MA Lighting Dimmer 2 x 12 x 2 Kw Set | |||||
80 | 3 | SLS DigiLight 36ch x 3 Kw Set | |||||
81 | 5 | SLS Dimmer DigiLight 24ch x 3 Kw A Set(2x12ch) | |||||
82 | 4 | SLS Dimmer DigiLight 24ch x 3 Kw B Set (1x12-2x6ch) | |||||
83 | |||||||
84 | |||||||
85 | Stock | Dimmer | Book | Daily Rate | |||
86 | |||||||
87 | 4 | Atel Lights 6ch Dimmer 6 x 2 Kw | |||||
88 | 1 | Celco Fusion Dimmer 12ch x 2 Kw | |||||
89 | 6 | Electron 6Ch x 3 Kw Dimmerpack E1550DC | |||||
90 | 10 | Electron Actor 616 6 x 3 Kw | |||||
91 | 3 | Electron Actor 625 6 x 5 Kw | |||||
92 | 1 | Electron Actor E1550 6ch x 5 Kw | |||||
93 | 8 | FOS Technologies 1CH. Dimmer | |||||
94 | 4 | SLS DigiLight 6ch x 3 Kw | |||||
95 | 1 | SLS DigiLight 12ch x 3 Kw | |||||
96 | |||||||
97 | |||||||
98 | |||||||
99 | Stock | Book | Daily Rate | ||||
100 | |||||||
101 | |||||||
102 | |||||||
103 | |||||||
104 | |||||||
105 | |||||||
106 | |||||||
107 | |||||||
108 | |||||||
109 | |||||||
110 | |||||||
111 | |||||||
112 | |||||||
113 | |||||||
114 | |||||||
1.Power Distribution - Dimmer |
Thank you in advance!