VBE313
Well-known Member
- Joined
- Mar 22, 2019
- Messages
- 686
- Office Version
- 365
- Platform
- Windows
What is a less rigorous way or writing this?
Code:
Sub COSTPLANBREAKDOWN()
Dim rngstart As Range
Dim tst As Range, lastrow As Long
Dim cl As Object
Dim L As Long, strcells As String, lsr As String, toplvl As String, comm As String, flat As String
Dim CLT As String, PLT As String, CLST As String, pmark As String, pbrk As String, dmnsl As String, final As String
Dim Subcon1 As String, Subcon2 As String, Subcon3 As String, Subcon4 As String, Subcon5 As String
Dim SubQty1 As String, SubQty2 As String, SubQty3 As String, SubQty4 As String, SubQty5 As String
Dim SubComm1 As String, SubComm2 As String, SubComm3 As String, SubComm4 As String, SubComm5 As String
Dim SubPart1 As String, SubPart2 As String, SubPart3 As String, SubPart4 As String, SubPart5 As String
Application.ScreenUpdating = False
Sheets("Export").Range("H6").Select
lsr = "LSR_01"
flat = "FLAT_I"
pmark = "P_MARK"
pbrk = "P_BRK1"
dmnsl = "DIM_1"
final = "FIN_I"
Set rngstart = ActiveCell
For Each cl In Sheets("Export").Range("H:H")
If ActiveCell.Value = "" Then
Sheets("Planning").Select
Application.ScreenUpdating = True
Exit Sub
Else
If ActiveCell.Value = "TOP LEVEL" And Subcon1 <> "" Or Subcon2 <> "" Or Subcon3 <> "" Or Subcon4 <> "" Or Subcon5 <> "" Then
toplvl = ActiveCell.Offset(0, -2).Value
Sheets("Planning").Select
lastrow = Cells(Rows.Count, 5).End(xlUp).Row
Cells(lastrow, 5).Offset(1, 0).Select
If Subcon1 <> "" Then
ActiveCell.Value = SubPart1
ActiveCell.Offset(0, 1).Value = 9400
ActiveCell.Offset(0, 2).Value = "RWRK"
ActiveCell.Offset(0, 3).Value = SubComm1
ActiveCell.Offset(0, 4).Value = "0200"
ActiveCell.Offset(0, 5).Value = "0.01"
ActiveCell.Offset(0, 6).Value = "MN"
ActiveCell.Offset(1, 0).Value = SubPart1
ActiveCell.Offset(1, 1).Value = 9500
ActiveCell.Offset(1, 2).Value = "SUBBFF"
ActiveCell.Offset(1, 3).Value = SubComm1
ActiveCell.Offset(1, 4).Value = "0200"
ActiveCell.Offset(1, 5).Value = ".01"
ActiveCell.Offset(1, 6).Value = "MN"
ActiveCell.Offset(2, 0).Value = SubPart1
ActiveCell.Offset(2, 1).Value = 10
ActiveCell.Offset(2, 2).Value = "SUBCON"
ActiveCell.Offset(2, 3).Value = SubComm1
ActiveCell.Offset(2, 4).Value = 1300
ActiveCell.Offset(2, 5).Value = "COST TO PROCESS"
ActiveCell.Offset(2, 6).Value = "MN"
ActiveCell.Offset(3, 0).Value = SubPart1
ActiveCell.Offset(3, 1).Value = 10
ActiveCell.Offset(3, 2).Value = "SUBCON"
ActiveCell.Offset(3, 3).Value = SubComm1
ActiveCell.Offset(3, 4).Value = "0200"
ActiveCell.Offset(3, 5).Value = "10"
ActiveCell.Offset(3, 6).Value = "DY"
ActiveCell.Offset(4, 0).Value = SubPart1
ActiveCell.Offset(4, 1).Value = 20
ActiveCell.Offset(4, 2).Value = "SHPBFF"
ActiveCell.Offset(4, 3).Value = SubComm1
ActiveCell.Offset(4, 4).Value = "0300"
ActiveCell.Offset(4, 5).Value = "5"
ActiveCell.Offset(4, 6).Value = "DY"
Subcon1 = ""
SubQty1 = ""
SubComm1 = ""
SubPart1 = ""
Else
End If
If Subcon2 <> "" Then
lastrow = Cells(Rows.Count, 5).End(xlUp).Row
Cells(lastrow, 5).Offset(1, 0).Select
ActiveCell.Value = SubPart2
ActiveCell.Offset(1, 0).Value = 20
ActiveCell.Offset(0, 2).Value = "SUBCON"
ActiveCell.Offset(0, 3).Value = SubComm2
ActiveCell.Offset(0, 4).Value = 1300
ActiveCell.Offset(0, 5).Value = "COST TO PROCESS"
ActiveCell.Offset(0, 6).Value = "MN"
ActiveCell.Offset(1, 0).Value = SubPart2
ActiveCell.Offset(1, 1).Value = 10
ActiveCell.Offset(1, 2).Value = "SUBCON"
ActiveCell.Offset(1, 3).Value = SubComm2
ActiveCell.Offset(1, 4).Value = "0200"
ActiveCell.Offset(1, 5).Value = "10"
ActiveCell.Offset(1, 6).Value = "DY"
Subcon2 = ""
SubQty2 = ""
SubComm2 = ""
SubPart2 = ""
Else
End If
If Subcon3 <> "" Then
lastrow = Cells(Rows.Count, 5).End(xlUp).Row
Cells(lastrow, 5).Offset(1, 0).Select
ActiveCell.Value = SubPart3
ActiveCell.Offset(1, 0).Value = 30
ActiveCell.Offset(0, 2).Value = "SUBCON"
ActiveCell.Offset(0, 3).Value = SubComm3
ActiveCell.Offset(0, 4).Value = 1300
ActiveCell.Offset(0, 5).Value = "COST TO PROCESS"
ActiveCell.Offset(0, 6).Value = "MN"
ActiveCell.Offset(1, 0).Value = SubPart3
ActiveCell.Offset(1, 1).Value = 10
ActiveCell.Offset(1, 2).Value = "SUBCON"
ActiveCell.Offset(1, 3).Value = SubComm3
ActiveCell.Offset(1, 4).Value = "0200"
ActiveCell.Offset(1, 5).Value = "10"
ActiveCell.Offset(1, 6).Value = "DY"
Subcon3 = ""
SubQty3 = ""
SubComm3 = ""
SubPart3 = ""
Else
End If
If Subcon4 <> "" Then
lastrow = Cells(Rows.Count, 5).End(xlUp).Row
Cells(lastrow, 5).Offset(1, 0).Select
ActiveCell.Value = SubPart4
ActiveCell.Offset(1, 0).Value = 40
ActiveCell.Offset(0, 2).Value = "SUBCON"
ActiveCell.Offset(0, 3).Value = SubComm4
ActiveCell.Offset(0, 4).Value = 1300
ActiveCell.Offset(0, 5).Value = "COST TO PROCESS"
ActiveCell.Offset(0, 6).Value = "MN"
ActiveCell.Offset(1, 0).Value = SubPart4
ActiveCell.Offset(1, 1).Value = 10
ActiveCell.Offset(1, 2).Value = "SUBCON"
ActiveCell.Offset(1, 3).Value = SubComm4
ActiveCell.Offset(1, 4).Value = "0200"
ActiveCell.Offset(1, 5).Value = "10"
ActiveCell.Offset(1, 6).Value = "DY"
Subcon4 = ""
SubQty4 = ""
SubComm4 = ""
SubPart4 = ""
Else
End If
If Subcon5 <> "" Then
lastrow = Cells(Rows.Count, 5).End(xlUp).Row
Cells(lastrow, 5).Offset(1, 0).Select
ActiveCell.Value = SubPart5
ActiveCell.Offset(1, 0).Value = 50
ActiveCell.Offset(0, 2).Value = "SUBCON"
ActiveCell.Offset(0, 3).Value = SubComm5
ActiveCell.Offset(0, 4).Value = 1300
ActiveCell.Offset(0, 5).Value = "COST TO PROCESS"
ActiveCell.Offset(0, 6).Value = "MN"
ActiveCell.Offset(1, 0).Value = SubPart5
ActiveCell.Offset(1, 1).Value = 10
ActiveCell.Offset(1, 2).Value = "SUBCON"
ActiveCell.Offset(1, 3).Value = SubComm5
ActiveCell.Offset(1, 4).Value = "0200"
ActiveCell.Offset(1, 5).Value = "10"
ActiveCell.Offset(1, 6).Value = "DY"
Subcon5 = ""
SubQty5 = ""
SubComm5 = ""
SubPart5 = ""
Else
End If
If ActiveSheet.Name <> "Export" Then
Sheets("Export").Select
Else
End If
Else
If ActiveCell.Value = "TOP LEVEL" Then
toplvl = ActiveCell.Offset(0, -2).Value
Debug.Print toplvl
Else
If ActiveCell.Value = "SUBCON" Then
If Subcon1 = "" Then
Subcon1 = ActiveCell.Offset(0, -1).Value
SubQty1 = ActiveCell.Offset(0, 3).Value
SubComm1 = ActiveCell.Offset(0, 19).Value
SubPart1 = toplvl
Else
If Subcon2 = "" Then
Subcon2 = ActiveCell.Offset(0, -1).Value
SubQty2 = ActiveCell.Offset(0, 3).Value
SubComm2 = ActiveCell.Offset(0, 19).Value
SubPart2 = toplvl
Else
If Subcon3 = "" Then
Subcon3 = ActiveCell.Offset(0, -1).Value
SubQty3 = ActiveCell.Offset(0, 3).Value
SubComm3 = ActiveCell.Offset(0, 19).Value
SubPart3 = toplvl
Else
If Subcon4 = "" Then
Subcon4 = ActiveCell.Offset(0, -1).Value
SubQty4 = ActiveCell.Offset(0, 3).Value
SubComm4 = ActiveCell.Offset(0, 19).Value
SubPart4 = toplvl
Else
If Subcon5 = "" Then
Subcon5 = ActiveCell.Offset(0, -1).Value
SubQty5 = ActiveCell.Offset(0, 3).Value
SubComm5 = ActiveCell.Offset(0, 19).Value
SubPart5 = toplvl
Else
End If
End If
End If
End If
End If
Else
If ActiveCell.Value = "LSR_01" Then
CLT = ActiveCell.Offset(0, 3).Value
PLT = ActiveCell.Offset(0, 6).Value
CLST = ActiveCell.Offset(0, 20).Value
comm = ActiveCell.Offset(0, 19).Value
Sheets("Planning").Activate
lastrow = Cells(Rows.Count, 5).End(xlUp).Row
Cells(lastrow, 5).Offset(1, 0).Select
ActiveCell.Value = toplvl & "A"
ActiveCell.Offset(1, 0).Value = toplvl & "A"
ActiveCell.Offset(2, 0).Value = toplvl & "A"
ActiveCell.Offset(3, 0).Value = toplvl & "A"
ActiveCell.Offset(0, 1).Value = "10"
ActiveCell.Offset(1, 1).Value = "10"
ActiveCell.Offset(2, 1).Value = "10"
ActiveCell.Offset(3, 1).Value = "10"
ActiveCell.Offset(0, 2).Value = lsr
ActiveCell.Offset(1, 2).Value = lsr
ActiveCell.Offset(2, 2).Value = lsr
ActiveCell.Offset(3, 2).Value = lsr
ActiveCell.Offset(0, 3).Value = comm
ActiveCell.Offset(1, 3).Value = comm
ActiveCell.Offset(2, 3).Value = comm
ActiveCell.Offset(3, 3).Value = comm
ActiveCell.Offset(0, 4).Value = 1300
ActiveCell.Offset(1, 4).Value = "0300"
ActiveCell.Offset(2, 4).Value = 1100
ActiveCell.Offset(3, 4).Value = "0300"
ActiveCell.Offset(0, 5).Value = CLT
ActiveCell.Offset(1, 5).Value = PLT
ActiveCell.Offset(2, 5).Value = CLST
ActiveCell.Offset(3, 5).Value = 5
ActiveCell.Offset(0, 6).Value = "MN"
ActiveCell.Offset(1, 6).Value = "MN"
ActiveCell.Offset(2, 6).Value = "MN"
ActiveCell.Offset(3, 6).Value = "DY"
Else
If ActiveCell.Value = "FLAT_I" Then
CLT = ActiveCell.Offset(0, 3).Value
PLT = ActiveCell.Offset(0, 6).Value
CLST = ActiveCell.Offset(0, 20).Value
comm = ActiveCell.Offset(0, 19).Value
Sheets("Planning").Activate
lastrow = Cells(Rows.Count, 5).End(xlUp).Row
Cells(lastrow, 5).Offset(1, 0).Select
ActiveCell.Value = toplvl & "A"
ActiveCell.Offset(1, 0).Value = toplvl & "A"
ActiveCell.Offset(2, 0).Value = toplvl & "A"
ActiveCell.Offset(3, 0).Value = toplvl & "A"
ActiveCell.Offset(0, 1).Value = "20"
ActiveCell.Offset(1, 1).Value = "20"
ActiveCell.Offset(2, 1).Value = "20"
ActiveCell.Offset(3, 1).Value = "20"
ActiveCell.Offset(0, 2).Value = flat
ActiveCell.Offset(1, 2).Value = flat
ActiveCell.Offset(2, 2).Value = flat
ActiveCell.Offset(3, 2).Value = flat
ActiveCell.Offset(0, 3).Value = comm
ActiveCell.Offset(1, 3).Value = comm
ActiveCell.Offset(2, 3).Value = comm
ActiveCell.Offset(3, 3).Value = comm
ActiveCell.Offset(0, 4).Value = 1300
ActiveCell.Offset(1, 4).Value = "0300"
ActiveCell.Offset(2, 4).Value = 1100
ActiveCell.Offset(3, 4).Value = "0300"
ActiveCell.Offset(0, 5).Value = CLT
ActiveCell.Offset(1, 5).Value = PLT
ActiveCell.Offset(2, 5).Value = CLST
ActiveCell.Offset(3, 5).Value = 2
ActiveCell.Offset(0, 6).Value = "MN"
ActiveCell.Offset(1, 6).Value = "MN"
ActiveCell.Offset(2, 6).Value = "MN"
ActiveCell.Offset(3, 6).Value = "DY"
Else
If ActiveCell.Value = "P_MARK" Then
CLT = ActiveCell.Offset(0, 3).Value
PLT = ActiveCell.Offset(0, 6).Value
CLST = ActiveCell.Offset(0, 20).Value
comm = ActiveCell.Offset(0, 19).Value
Sheets("Planning").Activate
lastrow = Cells(Rows.Count, 5).End(xlUp).Row
Cells(lastrow, 5).Offset(1, 0).Select
ActiveCell.Value = toplvl & "A"
ActiveCell.Offset(1, 0).Value = toplvl & "A"
ActiveCell.Offset(2, 0).Value = toplvl & "A"
ActiveCell.Offset(3, 0).Value = toplvl & "A"
ActiveCell.Offset(0, 1).Value = "30"
ActiveCell.Offset(1, 1).Value = "30"
ActiveCell.Offset(2, 1).Value = "30"
ActiveCell.Offset(3, 1).Value = "30"
ActiveCell.Offset(0, 2).Value = pmark
ActiveCell.Offset(1, 2).Value = pmark
ActiveCell.Offset(2, 2).Value = pmark
ActiveCell.Offset(3, 2).Value = pmark
ActiveCell.Offset(0, 3).Value = comm
ActiveCell.Offset(1, 3).Value = comm
ActiveCell.Offset(2, 3).Value = comm
ActiveCell.Offset(3, 3).Value = comm
ActiveCell.Offset(0, 4).Value = 1300
ActiveCell.Offset(1, 4).Value = "0300"
ActiveCell.Offset(2, 4).Value = 1100
ActiveCell.Offset(3, 4).Value = "0300"
ActiveCell.Offset(0, 5).Value = CLT
ActiveCell.Offset(1, 5).Value = PLT
ActiveCell.Offset(2, 5).Value = CLST
ActiveCell.Offset(3, 5).Value = 2
ActiveCell.Offset(0, 6).Value = "MN"
ActiveCell.Offset(1, 6).Value = "MN"
ActiveCell.Offset(2, 6).Value = "MN"
ActiveCell.Offset(3, 6).Value = "DY"
Else
If ActiveCell.Value = "P-BRK1" Or ActiveCell.Value = "P_BRK1" Then
CLT = ActiveCell.Offset(0, 3).Value
PLT = ActiveCell.Offset(0, 6).Value
CLST = ActiveCell.Offset(0, 20).Value
comm = ActiveCell.Offset(0, 19).Value
Sheets("Planning").Activate
lastrow = Cells(Rows.Count, 5).End(xlUp).Row
Cells(lastrow, 5).Offset(1, 0).Select
ActiveCell.Value = toplvl & "A"
ActiveCell.Offset(1, 0).Value = toplvl & "A"
ActiveCell.Offset(2, 0).Value = toplvl & "A"
ActiveCell.Offset(3, 0).Value = toplvl & "A"
ActiveCell.Offset(4, 0).Value = toplvl & "A"
ActiveCell.Offset(0, 1).Value = "40"
ActiveCell.Offset(1, 1).Value = "40"
ActiveCell.Offset(2, 1).Value = "40"
ActiveCell.Offset(3, 1).Value = "40"
ActiveCell.Offset(4, 1).Value = "40"
ActiveCell.Offset(0, 2).Value = pbrk
ActiveCell.Offset(1, 2).Value = pbrk
ActiveCell.Offset(2, 2).Value = pbrk
ActiveCell.Offset(3, 2).Value = pbrk
ActiveCell.Offset(4, 2).Value = pbrk
ActiveCell.Offset(0, 3).Value = comm
ActiveCell.Offset(1, 3).Value = comm
ActiveCell.Offset(2, 3).Value = comm
ActiveCell.Offset(3, 3).Value = comm
ActiveCell.Offset(4, 3).Value = comm
ActiveCell.Offset(0, 4).Value = 1300
ActiveCell.Offset(1, 4).Value = "0300"
ActiveCell.Offset(2, 4).Value = 1100
ActiveCell.Offset(3, 4).Value = 100
ActiveCell.Offset(4, 4).Value = "0300"
ActiveCell.Offset(0, 5).Value = CLT
ActiveCell.Offset(1, 5).Value = PLT
ActiveCell.Offset(2, 5).Value = CLST
ActiveCell.Offset(3, 5).Value = CLST
ActiveCell.Offset(4, 5).Value = 2
ActiveCell.Offset(0, 6).Value = "MN"
ActiveCell.Offset(1, 6).Value = "MN"
ActiveCell.Offset(2, 6).Value = "MN"
ActiveCell.Offset(3, 6).Value = "MN"
ActiveCell.Offset(4, 6).Value = "DY"
Else
If ActiveCell.Value = "DIM_1" Then
CLT = ActiveCell.Offset(0, 3).Value
PLT = ActiveCell.Offset(0, 6).Value
CLST = ActiveCell.Offset(0, 20).Value
comm = ActiveCell.Offset(0, 19).Value
Sheets("Planning").Activate
lastrow = Cells(Rows.Count, 5).End(xlUp).Row
Cells(lastrow, 5).Offset(1, 0).Select
ActiveCell.Value = toplvl & "A"
ActiveCell.Offset(1, 0).Value = toplvl & "A"
ActiveCell.Offset(2, 0).Value = toplvl & "A"
ActiveCell.Offset(3, 0).Value = toplvl & "A"
ActiveCell.Offset(0, 1).Value = "50"
ActiveCell.Offset(1, 1).Value = "50"
ActiveCell.Offset(2, 1).Value = "50"
ActiveCell.Offset(3, 1).Value = "50"
ActiveCell.Offset(0, 2).Value = dmnsl
ActiveCell.Offset(1, 2).Value = dmnsl
ActiveCell.Offset(2, 2).Value = dmnsl
ActiveCell.Offset(3, 2).Value = dmnsl
ActiveCell.Offset(0, 3).Value = comm
ActiveCell.Offset(1, 3).Value = comm
ActiveCell.Offset(2, 3).Value = comm
ActiveCell.Offset(3, 3).Value = comm
ActiveCell.Offset(0, 4).Value = 1300
ActiveCell.Offset(1, 4).Value = "0300"
ActiveCell.Offset(2, 4).Value = 1100
ActiveCell.Offset(3, 4).Value = "0300"
ActiveCell.Offset(0, 5).Value = CLT
ActiveCell.Offset(1, 5).Value = PLT
ActiveCell.Offset(2, 5).Value = CLST
ActiveCell.Offset(3, 5).Value = 2
ActiveCell.Offset(0, 6).Value = "MN"
ActiveCell.Offset(1, 6).Value = "MN"
ActiveCell.Offset(2, 6).Value = "MN"
ActiveCell.Offset(3, 6).Value = "DY"
Else
If ActiveCell.Value = "FIN_I" Then
CLT = ActiveCell.Offset(0, 3).Value
PLT = ActiveCell.Offset(0, 6).Value
CLST = ActiveCell.Offset(0, 20).Value
comm = ActiveCell.Offset(0, 19).Value
Sheets("Planning").Activate
lastrow = Cells(Rows.Count, 5).End(xlUp).Row
Cells(lastrow, 5).Offset(1, 0).Select
ActiveCell.Value = toplvl & "A"
ActiveCell.Offset(1, 0).Value = toplvl & "A"
ActiveCell.Offset(2, 0).Value = toplvl & "A"
ActiveCell.Offset(3, 0).Value = toplvl & "A"
ActiveCell.Offset(0, 1).Value = "60"
ActiveCell.Offset(1, 1).Value = "60"
ActiveCell.Offset(2, 1).Value = "60"
ActiveCell.Offset(3, 1).Value = "60"
ActiveCell.Offset(0, 2).Value = final
ActiveCell.Offset(1, 2).Value = final
ActiveCell.Offset(2, 2).Value = final
ActiveCell.Offset(3, 2).Value = final
ActiveCell.Offset(0, 3).Value = comm
ActiveCell.Offset(1, 3).Value = comm
ActiveCell.Offset(2, 3).Value = comm
ActiveCell.Offset(3, 3).Value = comm
ActiveCell.Offset(0, 4).Value = 1300
ActiveCell.Offset(1, 4).Value = "0300"
ActiveCell.Offset(2, 4).Value = 1100
ActiveCell.Offset(3, 4).Value = "0300"
ActiveCell.Offset(0, 5).Value = CLT
ActiveCell.Offset(1, 5).Value = PLT
ActiveCell.Offset(2, 5).Value = CLST
ActiveCell.Offset(3, 5).Value = 2
ActiveCell.Offset(0, 6).Value = "MN"
ActiveCell.Offset(1, 6).Value = "MN"
ActiveCell.Offset(2, 6).Value = "MN"
ActiveCell.Offset(3, 6).Value = "DY"
Else
If ActiveSheet.Name <> "Export" Then
Sheets("Export").Select
Else
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
If ActiveSheet.Name <> "Export" Then
Sheets("Export").Select
Else
End If
ActiveCell.Offset(1, 0).Select
Next cl
End Sub
Last edited by a moderator: