Private Sub CommandButton1_Click()
On Error Resume Next '<= generally not advisable for the whole procedure since it will mask all errors.
'<= it should be used and then reset with 'On Error Goto 0'
'<= around the portions of the code that require it.
Dim iWsRiOffset As Integer
Dim iWsKuOffset As Integer
Dim iLoop As Integer
iWsRiOffset = 0
iWsKuOffset = 0
Do While iLoop < 14
Set ws = Worksheets("ribakardin")
Set wsku = Worksheets("Kulu arvestus")
Application.Run "Sheet1.nim1"
With wsku
.Cells(5, 1 + iWsKuOffset).ClearContents
.Cells(32, 4 + iWsKuOffset).ClearContents
.Cells(23, 1 + iWsKuOffset).Formula = "=vLOOKUP(Ribakardin!F" & 11 + iWsRiOffset & ",Sheet1!A150:c192,3)"
.Cells(22, 1 + iWsKuOffset).Formula = "=vLookup(Ribakardin!i" & 11 + iWsRiOffset & ",Sheet1!a195:c208,3)"
.Cells(24, 1 + iWsKuOffset).Formula = "=vlookup(ribakardin!f" & 11 + iWsRiOffset & ",Sheet1!a22:c63,3)"
.Cells(25, 1 + iWsKuOffset).Formula = "=vLOOKUP(Ribakardin!e" & 11 + iWsRiOffset & ",Sheet1!a2:e19,5)"
.Cells(26, 1 + iWsKuOffset).Formula = "=vlookup(Ribakardin!e" & 11 + iWsRiOffset & ",sheet1!a2:c19,3)"
.Cells(27, 1 + iWsKuOffset).Formula = "=vlookup(Ribakardin!b" & 11 + iWsRiOffset & ",Sheet1!a66:c148,3)"
.Range("a14,a64,a114,h14,h64,h114,p14,p64,p114,x14,x64,x114,af14,af64").Font.Color = RGB(0, 0, 0)
End With
Select Case LCase(Sheets("ribakardin").Cells(11, 10 + iWsRiOffset).Value)
Case "1", "2", "3", "4", "5", "6"
Application.Run "Sheet1.magnet"
End Select
Select Case LCase(Sheets("Ribakardin").Range("D11").Value)
Case "25mm", "25", "25 mm"
Application.Run "Sheet1.mingi"
With wsku
.Range("b5").Value = "Aksel 4mm D-kujuline"
.Range("b6").Value = "Laagripukk rulliga"
.Range("b7").Value = "Rull valge"
.Range("b8").Value = "Rull must"
.Range("b9").Value = "Alaliistu otsik"
.Range("b11").Value = "Ülemise riba klamber"
.Range("b12").Value = "Akrüülpulga konks"
.Range("b13").Value = "Akrüülpulga otsik"
.Range("b14").Value = "Reduktor "
.Range("B15").Value = "Nöörilukk"
.Range("b16").Value = "Kelluke"
.Range("b17").Value = "Ülemise karbi otsik"
.Range("b18").Value = "põhjanupp"
.Range("B19").Value = "Nööriankur"
.Range("b20").Value = "Nöörijuhik"
.Range("B21").Value = "seadetross"
.Range("b23").Value = "Nöör 1,4mm"
.Range("b24").Value = "redel " & ws.Range("d11").Text + "mm"
.Range("B25").Value = "teras 42mm"
.Range("b26").Value = "teras 72mm"
.Range("b27").Value = "Ribi " + Worksheets("Ribakardin").Range("D11").Text + "mm"
.Range("c27").Value = (((Worksheets("Ribakardin").Range("p11").Value / 100) / 0.0214) * (Worksheets("Ribakardin").Range("o11").Value / 100)) * ws.Range("M11").Value
.Range("a5").Value = "125150"
.Range("a6").Value = "125200"
.Range("a7").Value = "125210"
.Range("a8").Value = "125220"
.Range("a9").Value = "125910"
.Range("a10").Value = "1253" + Worksheets("Ribakardin").Range("c11").Text
.Range("a11").Value = "125170A"
.Range("a12").Value = "125720"
.Range("a13").Value = "125710"
.Range("a14").Value = "125740"
.Range("a15").Value = "125750"
.Range("a16").Value = "125830"
.Range("a17").Value = "125160"
.Range("a18").Value = "125900"
.Range("a19").Value = "125820B"
.Range("a20").Value = "125810B"
.Range("a21").Value = "1254020B"
End With
End Select
Worksheets("Kulu arvestus").Range("B22").Value = "Seadehoob " + Worksheets("Ribakardin").Range("i11").Text
Worksheets("Kulu arvestus").Range("B10").Value = "Kinnitus " + Worksheets("Ribakardin").Range("C11").Text
If UCase(Left(ws.Range("c11").Value, 1)) >= "V" Then
Application.Run "Sheet1.V1"
Application.Run "Sheet1.Vk_1"
End If
If UCase(Left(Worksheets("Ribakardin").Range("C11").Value, 1)) <= "P" Then
Application.Run "Sheet1.P1"
ElseIf UCase(Left(Worksheets("Ribakardin").Range("C11").Value, 2)) >= "V6" Then
Application.Run "Sheet1.V1"
Application.Run "Sheet1.V6_1"
End If
Select Case LCase(Sheets("Ribakardin").Range("d11").Value)
Case "35mm", "35", "35 mm"
Application.Run "Sheet1.mingi2"
Application.Run "Sheet1.mm35_1"
End Select
Select Case LCase(Sheets("Ribakardin").Range("d11").Value)
Case "50", "50mm", "50 mm"
Application.Run "Sheet1.mingi2"
Application.Run "Sheet1.mm50_1"
End Select
Select Case LCase(Sheets("ribakardin").Range("a11").Value)
Case "PSK", "psk"
wsku.Range("a19").Value = "135830W01"
wsku.Range("b19").Value = "Puit" & wsku.Range("b19").Text
wsku.Range("c19").Value = 3 * ws.Range("m11").Value
Worksheets("Kulu arvestus").Range("b22").Value = _
"Puidust seadehoob " + Worksheets("ribakardin").Range("i11").Text
If wsku.Range("a22").Value <> " " Then
wsku.Range("b22").Value = ""
End If
Worksheets("Kulu arvestus").Range("b25").Value = "Puidust alaliist"
Worksheets("Kulu arvestus").Range("a25").Value = _
"1" + Worksheets("Ribakardin").Range("d11").Text + "WB" + _
Right(Worksheets("Ribakardin").Range("b11").Value, 2)
If ws.Range("D11").Value = "25" Then
If Right(Worksheets("Ribakardin").Range("b11").Value, 2) = "01" Then
Worksheets("Kulu arvestus").Range("a22").Value = "1255100W01"
ElseIf Right(Worksheets("Ribakardin").Range("b11").Value, 2) = "02" Then
Worksheets("Kulu arvestus").Range("a22").Value = "1255100W02"
ElseIf Right(Worksheets("Ribakardin").Range("b11").Value, 2) = "03" Then
Worksheets("kulu arvestus").Range("a22").Value = "1255100W03"
ElseIf Right(Worksheets("Ribakardin").Range("b11").Value, 2) = "04" Then
Worksheets("kulu arvestus").Range("a22").Value = "1255100W04"
ElseIf Right(Worksheets("Ribakardin").Range("b11").Value, 2) = "05" Then
Worksheets("Kulu arvestus").Range("a22").Value = "1255100W05"
ElseIf Right(Worksheets("Ribakardin").Range("b11").Value, 2) = "06" Then
Worksheets("Kulu arvestus").Range("a22").Value = "1255100W06"
End If
End If
If Right(Worksheets("Ribakardin").Range("e11").Value, 2) = "01" Then
Worksheets("Kulu arvestus").Range("a26").Value = "1X72S002"
ElseIf Right(Worksheets("Ribakardin").Range("e11").Value, 2) = "02" Then
Worksheets("Kulu arvestus").Range("a26").Value = "127S005"
ElseIf Right(Worksheets("Ribakardin").Range("e11").Value, 2) = "03" Then
Worksheets("Kulu arvestus").Range("A26").Value = "127S064"
End If
'Worksheets("kulu arvestus").Range("A9:D9").ClearContents
Worksheets("Kulu arvestus").Range("A12:D13").ClearContents
End Select
Select Case LCase(Sheets("Ribakardin").Range("A11").Value)
Case "INT", "int", "Int"
Application.Run "Sheet1.INT1"
End Select
iWsRiOffset = iWsRiOffset + 1
iWsKuOffset = iWsKuOffset + 50
iLoop = iLoop + 1
Loop
End Sub