Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub SEMACO()
- Dim x As Integer
- Dim row As Integer
- Dim typ As String
- Dim specificType As String
- Dim price As Double
- Dim hours As String
- Dim totalPrice As Double
- Dim totalHours As Double
- Dim visited As Boolean
- Dim tableStart As Integer
- Dim tableWidth As Integer
- Dim tableEnd As Integer
- Dim highlightedRows(10) As Integer
- Dim i As Integer
- Dim j As Integer
- Dim sum1 As Double
- Dim sum2 As Double
- Dim sum3 As Double
- Dim sum4 As Double
- Dim sum5 As Double
- Dim shipPrice As Double
- Dim packPrice As Double
- x = 2
- row = 7
- price = 0
- hours = 0
- totalPrice = 0
- totalHours = 0
- visited = False
- tableStart = row - 2
- tableWidth = 6
- i = 0
- j = 0
- sum1 = 0
- sum2 = 0
- sum3 = 0
- sum4 = 0
- sum5 = 0
- shipPrice = 0
- packPrice = 0
- '-------Predvyroba
- typ = Mid(GetValue("M000447", x), 2, 1)
- While typ = "1"
- specificType = GetValue("M000447", x)
- Do While GetValue("M000447", x) = specificType
- price = price + CDbl(GetValue("M000162", x))
- hours = hours + CDbl(GetValue("M000161", x) / 60)
- x = x + 1
- Loop
- Sheets(1).Cells(row, 1) = specificType
- Sheets(1).Cells(row, 2) = hours
- Sheets(1).Cells(row, 3) = price
- totalPrice = totalPrice + price
- totalHours = totalHours + hours
- price = 0
- hours = 0
- typ = Mid(GetValue("M000447", x), 2, 1)
- row = row + 1
- visited = True
- Wend
- If visited Then
- Sheets(1).Cells(row, 1) = "Předvýroba"
- Sheets(1).Cells(row, 2) = totalHours
- Sheets(1).Cells(row, 3) = totalPrice
- highlightedRows(i) = row
- i = i + 1
- BoldRow (row)
- visited = False
- row = row + 1
- End If
- sum1 = sum1 + totalHours
- sum2 = sum2 + totalPrice
- totalHours = 0
- totalPrice = 0
- '-------Vyroba
- While typ = "2"
- specificType = GetValue("M000447", x)
- Do While GetValue("M000447", x) = specificType
- price = price + CDbl(GetValue("M000162", x))
- hours = hours + CDbl(GetValue("M000161", x) / 60)
- x = x + 1
- Loop
- Sheets(1).Cells(row, 1) = specificType
- Sheets(1).Cells(row, 2) = hours
- Sheets(1).Cells(row, 3) = price
- totalPrice = totalPrice + price
- totalHours = totalHours + hours
- price = 0
- hours = 0
- typ = Mid(GetValue("M000447", x), 2, 1)
- row = row + 1
- visited = True
- Wend
- If visited Then
- Sheets(1).Cells(row, 1) = "Výroba"
- Sheets(1).Cells(row, 2) = totalHours
- Sheets(1).Cells(row, 3) = totalPrice
- highlightedRows(i) = row
- i = i + 1
- BoldRow (row)
- visited = False
- row = row + 1
- End If
- sum1 = sum1 + totalHours
- sum2 = sum2 + totalPrice
- totalHours = 0
- totalPrice = 0
- '--------Manufacturing
- While typ = "3"
- specificType = GetValue("M000447", x)
- Do While GetValue("M000447", x) = specificType
- price = price + CDbl(GetValue("M000162", x))
- hours = hours + CDbl(GetValue("M000161", x) / 60)
- x = x + 1
- Loop
- Sheets(1).Cells(row, 1) = specificType
- Sheets(1).Cells(row, 2) = hours
- Sheets(1).Cells(row, 3) = price
- totalPrice = totalPrice + price
- totalHours = totalHours + hours
- price = 0
- hours = 0
- typ = Mid(GetValue("M000447", x), 2, 1)
- row = row + 1
- visited = True
- Wend
- If visited Then
- Sheets(1).Cells(row, 1) = "Manufacturing"
- Sheets(1).Cells(row, 2) = totalHours
- Sheets(1).Cells(row, 3) = totalPrice
- BoldRow (row)
- highlightedRows(i) = row
- i = i + 1
- visited = False
- row = row + 1
- End If
- sum1 = sum1 + totalHours
- sum2 = sum2 + totalPrice
- totalHours = 0
- totalPrice = 0
- '--------Testing mold (neni vyzkouseno)
- While typ = "4"
- specificType = GetValue("M000447", x)
- Do While GetValue("M000447", x) = specificType
- price = price + CDbl(GetValue("M000162", x))
- hours = hours + CDbl(GetValue("M000161", x) / 60)
- x = x + 1
- Loop
- Sheets(1).Cells(row, 1) = specificType
- Sheets(1).Cells(row, 2) = hours
- Sheets(1).Cells(row, 3) = price
- totalPrice = totalPrice + price
- totalHours = totalHours + hours
- price = 0
- hours = 0
- typ = Mid(GetValue("M000447", x), 2, 1)
- row = row + 1
- visited = True
- Wend
- If visited Then
- Sheets(1).Cells(row, 1) = "Manufacturing"
- Sheets(1).Cells(row, 2) = totalHours
- Sheets(1).Cells(row, 3) = totalPrice
- BoldRow (row)
- highlightedRows(i) = row
- i = i + 1
- visited = False
- row = row + 1
- End If
- sum1 = sum1 + totalHours
- sum2 = sum2 + totalPrice
- totalHours = 0
- totalPrice = 0
- '-------Hruby material
- typ = GetValue("M000449", x)
- While typ = "2"
- specificType = GetValue("M000447", x)
- Do While GetValue("M000447", x) = specificType
- If GetValue("M004725", x) <> "" Then
- price = price + CDbl(GetValue("M004725", x))
- ElseIf GetValue("M000162", x) <> "" Then
- price = price + CDbl(GetValue("M000162", x))
- Else
- price = price + 0
- End If
- x = x + 1
- Loop
- Sheets(1).Cells(row, 1) = specificType
- Sheets(1).Cells(row, 4) = price
- totalPrice = totalPrice + price
- price = 0
- typ = GetValue("M000449", x)
- row = row + 1
- visited = True
- Wend
- If visited Then
- Sheets(1).Cells(row, 1) = "Hrubý materiál"
- Sheets(1).Cells(row, 4) = totalPrice
- highlightedRows(i) = row
- i = i + 1
- BoldRow (row)
- visited = False
- row = row + 1
- End If
- sum3 = sum3 + totalPrice
- totalHours = 0
- totalPrice = 0
- '-------Nakupovany material
- While typ = "3"
- specificType = GetValue("M000447", x)
- Do While GetValue("M000447", x) = specificType
- If GetValue("M004725", x) <> "" Then
- price = price + CDbl(GetValue("M004725", x))
- ElseIf GetValue("M000162", x) <> "" Then
- price = price + CDbl(GetValue("M000162", x))
- Else
- price = price + 0
- End If
- x = x + 1
- Loop
- Sheets(1).Cells(row, 1) = specificType
- Sheets(1).Cells(row, 4) = price
- totalPrice = totalPrice + price
- price = 0
- typ = GetValue("M000449", x)
- row = row + 1
- visited = True
- Wend
- If visited Then
- Sheets(1).Cells(row, 1) = "Nakupovaný materiál"
- Sheets(1).Cells(row, 4) = totalPrice
- highlightedRows(i) = row
- i = i + 1
- BoldRow (row)
- visited = False
- row = row + 1
- End If
- sum3 = sum3 + totalPrice
- totalHours = 0
- totalPrice = 0
- '-------Kooperace
- While typ = "4"
- specificType = GetValue("M000447", x)
- If specificType = "ship" Then
- If GetValue("M004725", x) <> "" Then
- shipPrice = shipPrice + CDbl(GetValue("M004725", x))
- ElseIf GetValue("M000162", x) <> "" Then
- shipPrice = shipPrice + CDbl(GetValue("M000162", x))
- Else
- shipPrice = shipPrice + 0
- End If
- x = x + 1
- ElseIf specificType = "pack" Then
- If GetValue("M004725", x) <> "" Then
- packPrice = packPrice + CDbl(GetValue("M004725", x))
- ElseIf GetValue("M000162", x) <> "" Then
- packPrice = packPrice + CDbl(GetValue("M000162", x))
- Else
- packPrice = packPrice + 0
- End If
- x = x + 1
- Else
- Do While GetValue("M000447", x) = specificType
- If GetValue("M004725", x) <> "" Then
- price = price + CDbl(GetValue("M004725", x))
- ElseIf GetValue("M000162", x) <> "" Then
- price = price + CDbl(GetValue("M000162", x))
- Else
- price = price + 0
- End If
- hours = hours + CDbl(GetValue("M000161", x) / 60)
- x = x + 1
- Loop
- Sheets(1).Cells(row, 1) = specificType
- Sheets(1).Cells(row, 5) = hours
- Sheets(1).Cells(row, 6) = price
- totalPrice = totalPrice + price
- totalHours = totalHours + hours
- row = row + 1
- visited = True
- End If
- price = 0
- hours = 0
- typ = GetValue("M000449", x)
- Wend
- If visited Then
- Sheets(1).Cells(row, 1) = "Kooperace"
- Sheets(1).Cells(row, 5) = totalHours
- Sheets(1).Cells(row, 6) = totalPrice
- highlightedRows(i) = row
- i = i + 1
- BoldRow (row)
- visited = False
- row = row + 1
- End If
- sum4 = sum4 + totalHours
- sum5 = sum5 + totalPrice
- totalHours = 0
- totalPrice = 0
- '-------Ostatni
- If packPrice <> 0 Then
- Sheets(1).Cells(row, 1) = "pack"
- Sheets(1).Cells(row, 6) = packPrice
- row = row + 1
- visited = True
- End If
- If shipPrice <> 0 Then
- Sheets(1).Cells(row, 1) = "ship"
- Sheets(1).Cells(row, 6) = shipPrice
- row = row + 1
- visited = True
- End If
- If visited Then
- Sheets(1).Cells(row, 1) = "Ostatní"
- Sheets(1).Cells(row, 6) = packPrice + shipPrice
- highlightedRows(i) = row
- i = i + 1
- BoldRow (row)
- visited = False
- End If
- sum5 = sum5 + packPrice + shipPrice
- row = row + 1
- tableEnd = row
- Sheets(1).Cells(row, 1) = "Total sum"
- Sheets(1).Cells(row, 2) = sum1
- Sheets(1).Cells(row, 3) = sum2
- Sheets(1).Cells(row, 4) = sum3
- Sheets(1).Cells(row, 5) = sum4
- Sheets(1).Cells(row, 6) = sum5
- BoldRow (row)
- row = row + 1
- Sheets(1).Cells(row, 1) = "Total Costs"
- Sheets(1).Cells(row, 2) = sum3 + sum5
- BoldRow (row)
- row = row + 1
- Sheets(1).Cells(row, 1) = "Forecast Costs"
- Sheets(1).Cells(row, 2) = sum2
- BoldRow (row)
- '-------Kresleni ohraniceni
- For i = 0 To tableWidth - 1
- Call MakeFrame(tableStart, i + 1, tableEnd, i + 1)
- Next i
- Call MakeFrame(tableStart, 1, tableStart + 1, tableWidth)
- For i = LBound(highlightedRows) To UBound(highlightedRows)
- If highlightedRows(i) <> 0 Then
- For j = 0 To tableWidth - 1
- Call RemoveFrame(highlightedRows(i), j + 1, highlightedRows(i), j + 2)
- Next j
- Call MakeFrame(highlightedRows(i), 1, highlightedRows(i), tableWidth)
- End If
- Next i
- End Sub
- Function BoldRow(row As Integer)
- Sheets(1).Cells(row, 1).EntireRow.Font.Bold = True
- End Function
- Function MakeFrame(row1 As Integer, col1 As Integer, row2 As Integer, col2 As Integer)
- Sheets(1).Range(Sheets(1).Cells(row1, col1), Sheets(1).Cells(row2, col2)).Borders(xlEdgeBottom).LineStyle = xlContinuous
- Sheets(1).Range(Sheets(1).Cells(row1, col1), Sheets(1).Cells(row2, col2)).Borders(xlEdgeRight).LineStyle = xlContinuous
- Sheets(1).Range(Sheets(1).Cells(row1, col1), Sheets(1).Cells(row2, col2)).Borders(xlEdgeTop).LineStyle = xlContinuous
- Sheets(1).Range(Sheets(1).Cells(row1, col1), Sheets(1).Cells(row2, col2)).Borders(xlEdgeLeft).LineStyle = xlContinuous
- End Function
- Function RemoveFrame(row1 As Integer, col1 As Integer, row2 As Integer, col2 As Integer)
- Sheets(1).Range(Sheets(1).Cells(row1, col1), Sheets(1).Cells(row2, col2)).Borders(xlEdgeBottom).LineStyle = xlNone
- Sheets(1).Range(Sheets(1).Cells(row1, col1), Sheets(1).Cells(row2, col2)).Borders(xlEdgeRight).LineStyle = xlNone
- Sheets(1).Range(Sheets(1).Cells(row1, col1), Sheets(1).Cells(row2, col2)).Borders(xlEdgeTop).LineStyle = xlNone
- Sheets(1).Range(Sheets(1).Cells(row1, col1), Sheets(1).Cells(row2, col2)).Borders(xlEdgeLeft).LineStyle = xlNone
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement