Public Sub Paivita()
Application.ScreenUpdating = False
On Error Resume Next
Dim BoxArray As Variant
ReDim BoxArray(0)
Worksheets("ABB VSD Protection Guide").UnitBox.List = BoxArray
'BoxArray = HaeLaitteet(BoxArray)
BoxArray = haeTuotePerheet(BoxArray)
Worksheets("ABB VSD Protection Guide").DriveBox.List = BoxArray
Dim OptionArray As Variant
ReDim OptionArray(0)
'OptionArray = HaeOptiot(OptionArray)
Worksheets("ABB VSD Protection Guide").OptionBox.List = OptionArray
Worksheets("ABB VSD Protection Guide").OptionBox.Value = ""
Worksheets("ABB VSD Protection Guide").DriveBox.Value = ""
Worksheets("ABB VSD Protection Guide").UnitBox.Value = ""
Rows(10).ClearContents
Sheets("ABB VSD Protection Guide").Select
Cells(10, 1).Select
End Sub
Private Function haeTuotePerheet(BoxAr)
Application.ScreenUpdating = False
On Error Resume Next
For k = 2 To Sheets.Count
Sheets(k).Select
If UCase(Left(ActiveSheet.Name, 2)) = "AC" Then
For i = 9 To ActiveSheet.UsedRange.Rows.Count
If Left(Cells(i, 1).Value, 2) = "AC" Then
code = Cells(i, 1).Value
lCount = 0
prdFam = ""
For j = 1 To Len(code)
If Mid(code, j, 1) = "-" Then lCount = lCount + 1
If lCount = 1 And (Mid(code, 1, 6) = "ACS580" Or Mid(code, 1, 6) = "ACQ580" Or Mid(code, 1, 6) = "ACH580") Then
prdFam = Left(code, j - 1)
Exit For
End If
If lCount = 2 Then
prdFam = Left(code, j - 1)
Exit For
End If
Next j
incl = True
For j = 0 To UBound(BoxAr) - 1
If BoxAr(j) = prdFam Then incl = False
Next j
If incl And prdFam <> "" Then
ReDim Preserve BoxAr(UBound(BoxAr) + 1)
BoxAr(UBound(BoxAr) - 1) = prdFam
End If
End If
Next i
End If
Next k
haeTuotePerheet = BoxAr
End Function
Public Function HaeLaitteet(BoxAr, prdFam)
Application.ScreenUpdating = False
On Error Resume Next
srcSheet = ActiveSheet.Name
'Sheets("ACS850_ACSM1_ACQ810").Select
For j = 2 To Sheets.Count
Sheets(j).Select
If UCase(Left(ActiveSheet.Name, 2)) = "AC" Then
pituus = Len(prdFam)
For i = 9 To ActiveSheet.UsedRange.Rows.Count
If Left(Cells(i, 1), pituus) = prdFam Then
ReDim Preserve BoxAr(UBound(BoxAr) + 1)
BoxAr(UBound(BoxAr) - 1) = Cells(i, 1).Value
End If
Next i
End If
Next j
Sheets(srcSheet).Select
HaeLaitteet = BoxAr
End Function
Public Function UpdateOptions(ar, prdFam)
srcSheet = ActiveSheet.Name
trgSht = ""
For i = 2 To Sheets.Count
Sheets(i).Select
If UCase(Left(ActiveSheet.Name, 2)) = "AC" Then
pituus = Len(prdFam)
For j = 9 To ActiveSheet.UsedRange.Rows.Count
If Left(Cells(j, 1), pituus) = prdFam Then
trgSht = i
Exit For
End If
Next j
If trgSht <> "" Then Exit For
End If
Next i
If trgSht <> "" Then ar = HaeOptiot(ar, trgSht)
Sheets(srcSheet).Select
UpdateOptions = ar
End Function
Private Function HaeOptiot(OptAr, trgSht)
Application.ScreenUpdating = False
On Error Resume Next
Sheets(trgSht).Select
TargetCol = 6
TargetRow = 4
For i = TargetCol To ActiveSheet.UsedRange.Columns.Count
If Cells(1, i).Value <> "" Then
Category = Cells(1, i).Value
ReDim Preserve OptAr(UBound(OptAr, 1) + 1)
OptAr(UBound(OptAr, 1) - 1) = Category
End If
Next i
HaeOptiot = OptAr
End Function
Public Sub CollectOptions()
Application.ScreenUpdating = False
On Error Resume Next
Found = 0
If Worksheets("ABB VSD Protection Guide").UnitBox.Value <> "" And Worksheets("ABB VSD Protection Guide").OptionBox.Value <> "" Then
drive = Worksheets("ABB VSD Protection Guide").UnitBox.Value
Optio = Worksheets("ABB VSD Protection Guide").OptionBox.Value
If Worksheets("ABB VSD Protection Guide").OptionButton1.Value = -1 Then
Voltage = 230
Else
Voltage = 115
End If
For i = 2 To Sheets.Count
Sheets(i).Select
Columns(1).Select
On Error GoTo findError
Selection.Find(What:=drive, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
On Error Resume Next
DriveRow = ActiveCell.Row
trgSheet = ActiveSheet.Name
Exit For
findResume:
Next i
Rows(1).Select
Selection.Find(What:=Optio, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
OptionCol = ActiveCell.Column
For i = OptionCol To 255
Part = ""
Volt = ""
Qty = ""
Sheets(trgSheet).Select
If Cells(1, i).Value <> Optio And Cells(1, i).Value <> "" Then GoTo TheEnd
If Cells(DriveRow, i).Value <> "" Then
If Cells(6, i).Value Like "*" & Voltage & "*" Then
PartCat = Cells(4, i).Value
Part = Cells(5, i).Value
Volt = Cells(6, i).Value
Qty = Cells(DriveRow, i).Value
TechnicalData = Cells(8, i).Value
PartNumber = Cells(7, i).Value
Else
GoTo hyppy
End If
Sheets("ABB VSD Protection Guide").Select
aa = 10
kierto:
If Cells(aa, 1).Value = "" Then
Cells(aa, 1).Value = drive
Cells(aa, 2).Value = Volt
Cells(aa, 2).HorizontalAlignment = xlCenter
Cells(aa, 3).Value = Optio
Cells(aa, 4).Value = PartCat
Cells(aa, 5).Value = Part
Cells(aa, 6).Value = Qty
Cells(aa, 6).HorizontalAlignment = xlCenter
Cells(aa, 8).Value = TechnicalData
Cells(aa, 7).Value = PartNumber
Range(Cells(aa, 1), Cells(aa, 10)).WrapText = True
Else
aa = aa + 1
GoTo kierto
End If
Sheets(trgSheet).Select
End If
hyppy:
Next i
End If
GoTo TheEnd
findError:
Resume findResume
TheEnd:
Sheets("ABB VSD Protection Guide").Select
End Sub
Public Sub ClearArea()
Range(Cells(10, 1), Cells(1000, 10)).Clear
Call Paivita
End Sub