'續張型號工作表作運算----------------------------------------------------------
Dim WsName, N, i, j, K As Integer '不同工作表
Dim X, Y, Z As Integer '自身工作表的範圍
Dim Sh As Worksheet 'Dim(宣告變數為私用變數) 型態為 Worksheet(工作表)
'移除所有Sh(工作表)的Hyperlinks(超連結集合物件)刪除----------------------------
For Each Sh In Sheets
Sh.Hyperlinks.Delete
Next
'先Delete所有舊Record!---------------------------------------------------------
X = 4: Y = Range("A65536").End(xlUp).Row
Range("A4:D" & Y).Hyperlinks.Delete
Range("A4:D" & Y).ClearContents
'設定所有型號Sheet中,以最Updata的方法計算因 Out 而引致的 負數Total 記錄------------
N = Worksheets.Count
For WsName = 3 To N
Sheets(WsName).Activate
i = Sheets(WsName).Range("IV3").End(xlToLeft).Column
For j = 2 To i
If Sheets(WsName).Cells(3, j).Value = "Out" Then
For K = 4 To Sheets(WsName).Range("A65536").End(xlUp).Row
If Sheets(WsName).Cells(K, j).Value <> "" And Sheets(WsName).Cells(K, j + 1) < 0 Then
'抄 data進去, 讀出對應路徑 及 超連結 ---------------
Cells(X, "A").Value = Sheets(WsName).Cells(K, 1)
Cells(X, "B").Value = Sheets(WsName).Cells(1, j - 2)
Cells(X, "C").Value = Sheets(WsName).Cells(K, j + 1)
Cells(X, "D").Value = Sheets(WsName).Name & "!" & Sheets(WsName).Cells(K, j + 1). _
Address(RowAbsolute:=False, ColumnAbsolute:=False)
With Sheets(2)
.Hyperlinks.Add Anchor:=.Cells(X, "D"), _
Address:="", _
SubAddress:=.Cells(X, "D").Value, _
TextToDisplay:=.Cells(X, "D").Value
End With
X = X + 1
End If
Next K
End If
Next j
Next WsName