Skip to content
Rain Hu's Workspace
Go back

[IDAS+] Optimize Summary Table Function

Rain Hu

前言

想法

做法

產生 Dictionary 物件

Dim SpecDict As Object ' Claim a dict to store spec rows in worksheet SPEC.
Dim DataDict As Object ' Claim a dict to store rawdata rows in worksheet Data.

Set SpecDict = CreateObject("Scripting.Dictionary")
Set DataDict = CreateObject("Scripting.Dictionary")

Call setDict("SPEC", 3, SpecDict, Worksheets("SPEC").UsedRange, True)
Call setDict("Data", 2, DataDict, Range(Worksheets("Data").Names(1)), True)

實作 setDict() 函數

Public Function setDict(ByVal sheetName As String, ByVal Target As Integer, ByRef Dict As Object, ByVal mRange As Range, Optional ByVal byRows As Boolean = True)
    
    Dim nowSheet As Worksheet
    If Not IsExistSheet(sheetName) Then Exit Function
    Set nowSheet = Worksheets(sheetName)
    
    Dim i As Long
    Dim n As Long

    On Error Resume Next
    
    If byRows = True Then
        For i = 1 To mRange.Rows.Count
            If Not Trim(mRange.Cells(i, Target).Value) = "" Then
                Dict.Add mRange.Cells(i, Target).Value, i
            End If
        Next i
    Else
        For i = 1 To mRange.Columns.Count
            If Not Trim(mRange.Cells(Target, i).Value) = "" Then
                Dict.Add mRange.Cells(Target, i).Value, i
            End If
        Next i
    End If
    
End Function

對 getSPECByPara() 做重製

Public Function getSPECByPara(ByVal nowPara As String, ByVal n As specColumn, Optional sheetName As String = "SPECTEMP")

    Dim reValue
    Dim nowRange As Range
    Dim TargetSheet As Worksheet
   
    If Left(nowPara, 1) = "'" Then nowPara = Mid(nowPara, 2)
   
    Set TargetSheet = Worksheets(sheetName)
    Set nowRange = TargetSheet.UsedRange
    On Error Resume Next
    reValue = TargetSheet.Cells(SpecDict(nowPara), n)
    If Not IsEmpty(reValue) Then
        If Trim(reValue) = "" Then Set reValue = Nothing
    End If
    getSPECByPara = reValue
End Function

對 getRangeByPara() 做重製

Public Function getRangeByPara(nowWafer As String, nowPara As String, Optional dieNum As Integer = 0)
    Dim nowRow As Long
    Dim nowRange As Range
   
    Set nowRange = Worksheets("Data").Range("wafer_" & nowWafer)
    Set getRangeByPara = Nothing
    
    If DataDict.Exists(nowPara) Then
        nowRow = DataDict(nowPara)
        Set getRangeByPara = nowRange.Range(N2L(4) & CStr(nowRow) & ":" & N2L(dieNum + 3) & CStr(nowRow))
    End If
    
End Function

解析


Share this post on:

Previous
[C++] The C++ Standard Template Library(STL) - Container
Next
[C++] 如何產生 random 值