Я пытаюсь ввести больше операций / присваивать значения переменным и ячейкам в цикле For, однако я получаю ошибку «Объект не поддерживает это свойство или метод» из-за строки .Cells (. CurrentRowOffset - 1, 2) .Value = YesterdaysOpen .
Я знаю, что мне нужно это квалифицировать, но я подумал, что это было сделано в начале утверждения «С». Очевидно, что с учетом ошибки это не так, поэтому я попытался добавить .Range впереди, также добавив полный адрес
Worksheets("Data processing").Cells(.CurrentRowOffset - 1, 2).Value
но это вызывает ту же ошибку. Я чувствую, что что-то упустил в структуре цикла / синтаксиса, но не нашел сопоставимого примера, который я понимаю, здесь или через Google (поэтому я отправляю вопрос).
`With Worksheets("Data processing")
ClosingPrice200Array = .Range(.Cells(FirstRow, 5), .Cells(LastRow, 5)).Value 'pass the first range to the ClosingPrice200Array
LastRow = .Cells(.Rows.Count, 5).End(xlUp).Row ' this assigns the row number of the last used row in column 4 to the variable "LastRow"
LastRowOffset = (LastRow - FirstRow + 1) - MovingAverageLength 'This sets the distance from the end row far enough to stop
'calculating a FORWARD looking average. Even though it is historical data,
'it is working through the data in a forward looking manner,
'from earliest to latest. so it needs to stop roughly 200 rows
'before the end to make sure all the calculations contain at least
'200 data points
With .Cells(FirstRow, 5).Resize(MovingAverageLength) ' reference the first range to sum
For CurrentRowOffset = 0 To LastRowOffset 'defines a For loop starting from zero to
'the row 200 data points before the end of the data
Dma200current = WorksheetFunction.Average(.Offset(CurrentRowOffset))
.Cells(.CurrentRowOffset - 1, 2).Value = YesterdaysOpen
.Cells(.CurrentRowOffset - 1, 3).Value = YesterdaysHigh
.Cells(.CurrentRowOffset - 1, 4).Value = YesterdaysLow
.Cells(.CurrentRowOffset - 1, 5).Value = YesterdaysClose
.Cells(.CurrentRowOffset, 2).Value = TodaysOpen
.Cells(.CurrentRowOffset, 3).Value = TodaysHigh
.Cells(.CurrentRowOffset, 4).Value = TodaysLow
.Cells(.CurrentRowOffset, 5).Value = TodaysClose
.Cells(.Rows.Count).Offset(CurrentRowOffset, 5).Value = Dma200current
DMASlopeCurrent = (Dma200current - Dma200Tminus1) / Dma200Tminus1
.Cells(.Rows.Count).Offset(CurrentRowOffset, 6).Value = DMASlopeCurrent
Dma200Tminus1 = Dma200current
Next
End With
Конец
`