在这里,我调用一个子例程,它将为我做excel中的一些事情,我希望填充IQRef()
和IQRngRef()
:
Dim IQRef() As Variant
Dim IQRngRef() As Variant
CaptureExcelReferences xlWB, pivotSheetName, IQRef, IQRngRef
以下是Sub例程,它要求CaptureIQRefsLocally
填写IQRef()
和IQRngRef()
Private Sub CaptureExcelReferences(ByVal xlWB As Workbook, ByVal pivotSheetName As String, ByRef IQRef() As Variant, ByRef IQRngRef() As Variant)
Dim ShRef As Excel.Worksheet
Set ShRef = xlWB.Worksheets(pivotSheetName)
Dim colNumb As Long
colNumb = ShRef.Cells(1, ShRef.Columns.Count).End(xlToLeft).Column
ReDim IQRef(colNumb)
ReDim IQRngRef(colNumb)
Dim rowNumb As Long
rowNumb = ShRef.Cells(ShRef.Rows.Count, 1).End(xlUp).Row
CaptureIQRefsLocally ShRef, rowNumb, colNumb, IQRef, IQRngRef
IdentifyRolesAndScoresRows IQRngRef, rowNumb
End Sub
以下是实际填写IQRef()
和IQRngRef()
Private Sub CaptureIQRefsLocally(ByVal ShRef As Worksheet, ByVal rowNumb As Long, ByVal colNumb As Long, ByRef IQRef As Variant, ByRef IQRngRef As Variant)
'capture IQ references in arrays. Values for column titles in IQRef and full column Ranges in IQRngRef.
Dim iCol As Long
Dim alignIQNumbToArrayNumb
For iCol = 1 To colNumb
alignIQNumbToArrayNumb = iCol - 1
Set IQRngRef(alignIQNumbToArrayNumb) = ShRef.Range(ShRef.Cells(1, iCol), ShRef.Cells(rowNumb, iCol))
IQRef(alignIQNumbToArrayNumb) = ShRef.Cells(1, iCol).Value
'IsThisaKeyIQ IQRngref, IQRef
Next iCol
End Sub
IQRef
的一切正常,它被正确填充并完全和完全传回主Sub(每个数组槽都填充一个单元格的String,因此它为每个槽返回一个字符串。 )
对于IQRngRef
,每个插槽都填充了一个范围,结果不太好。在CaptureIQRefsLocally
中,它会被正确填充并正确地将值传递回CaptureExcelReferences
,它甚至可以正确地用于以下子IdentifyRolesAndScoresRows
(它不会在此子句中被修改完全没有,并且返回值时值仍然正确)...但是当它被传递回主子IQRngRef
时它是空的......是的。它看起来像这样:
发生这种情况的原因(正如我在输入时发现的那样)是因为我在这个sub之后关闭了excel工作簿和应用程序,所以我可以回到powerpoint工作(我只想进入excel,获取我需要的信息,将其存储在数组中并关闭它。)有没有办法在数组中保存所有相同的值并关闭excel应用程序?
答案 0 :(得分:0)
使用
IQRngRef(alignIQNumbToArrayNumb) = Application.Transpose(ShRef.Range(ShRef.Cells(1, iCol), ShRef.Cells(rowNumb, iCol)).Value)
这样每个IQRngRef插槽都会存储一维数组