我有一個非常簡單的 Sub,其中包含以下代碼 -
Sub UnitNetCheck()
Dim UnitValue As Integer
Dim NetArea As Long
If Not [COUNTA(F2:F250)=0] Then
For UnitValue = 2 To 250
Cells(UnitValue, 26) = Cells(UnitValue, 4) * Cells(UnitValue, 6)
If Cells(UnitValue, 26) = 0 Then
Cells(UnitValue, 26).Value = ""
Else
End If
Next
Else
NetArea = Cells(Rows.Count, 7).End(xlUp).Row
Worksheets("Sheet1").Range("Z2:Z" & NetArea).Value =
Application.Transpose(Worksheets("Sheet1").Range("G2:G250").Value)
End If
End Sub
這個子UnitNetCheck,現在它所做的就是將一些單元格與其他一些單元格相乘,并將值放在Z2:Z250.
我不想將值輸出到指定的特定范圍內,而是在其他代碼中使用輸出,而不將其填充在作業表上。
我想做的是稍后使用 sub 作為作業表 SUMIF 函式的一部分作為Sumif("defined range")("defined criteria")(UnitNetCheck Sub).
uj5u.com熱心網友回復:
為了保存資料供以后在代碼中使用,您需要創建一個陣列型別的模塊級變數(如其他語言中的全域變數)。
第一步是創建陣列,因此從 VBA Editor 選單中,選擇 Insert->Module,然后粘貼以下內容:
'Declare the array inside a module file
Dim CellData(250)
下一步是保存現有代碼中的資料,如下所示:
For UnitValue = 2 To 250
Cells(UnitValue, 26) = Cells(UnitValue, 4) * Cells(UnitValue, 6)
If Cells(UnitValue, 26) = 0 Then
Cells(UnitValue, 26).Value = ""
Else
'Save in array for later use
CellData(UnitValue) = Cells(UnitValue, 26).Value
End If
Next
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/344629.html
下一篇:如果為空,輸入檔案不運行功能
