0
我正在处理一个列表,并在VBA上进行所有计算,但是当我想将我的列表写入预定义范围时,我什么也得不到。以下是我正在使用的代码的一个示例。我没有发布实际的代码,因为它很长,但是这个例子有同样的问题。将数组写入一个范围
Option Explicit
Sub readArray()
Dim CoGrade() As Variant
Dim LastRow As Integer
Dim NPSeQuedan() As Variant
Dim SeQuedanRng As Range
'erases information from arrays if there was any
Erase CoGrade
Erase NPSeQuedan
'-------------------------------------------------------------------------
'find the last row on the data i want to read
LastRow = Range("b10000").End(xlUp).Row
'the relevant data starts on row 34
ArrayRows = LastRow - 34 + 1
'redifines the variables with the total numbers of stocks in the portfolio
ReDim CoGrade(ArrayRows, 1)
ReDim NPSeQuedan(ArrayRows, 1)
'reads each relevant number into its proper variable
CoGrade = Range(Cells(34, 2), Cells(LastRow, 2))
'' test
Set SeQuedanRng = Range(Cells(34, 13), Cells(34 + ArrayRows - 1,
13))
For a = 1 To ArrayRows
NPSeQuedan(a, 1) = CoGrade(a, 1)
Next
SeQuedanRng.Value = NPSeQuedan
'''
end sub
请给出[mcve]。你有许多未申报的和显然未初始化的变量(本身不是很好的编程习惯)以及其内容未被描述的电子表格。要弄清楚这里发生的事情是不可能的。 –
谢谢约翰,对不起,我懒洋洋的抄袭整个事情,而且(惊喜)我不是自己的编码员,所以我必须拥有世界上所有不好的编码习惯。 – Frank
您不需要复制所有内容 - 只需提供一个*自包含的* sub来说明问题。作为猜测,这个问题与你如何声明和初始化变量有关 - 这正是你没有显示的东西。 –