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來說明問題。作爲猜測,這個問題與你如何聲明和初始化變量有關 - 這正是你沒有顯示的東西。 –