我正在为excel中的特定股票获得市场支持。所以我想在另一个单元格中复制股票价格。因此,例如X = 56是在时间t1处的股票价格。我正在复制单元格中的56表示A50并且下次时间t2股票价格变化并且我在单元格中复制说A 51并且它继续。我写了代码,但我收到了错误。
Sub CopyOpenItems()
Dim wbTarget
Dim wbThis
Dim WTF As Long
Dim FTW As Long
Dim X As Integer
X = 0
Set wbThis = ActiveWorkbook
Set wbTarget = ActiveWorkbook
ThisWorkbook.Sheets("Equity").Activate
FTW = Cells(151, "F").Value
WTF = Cells(X, "F").Value
Do While ActiveCell.Value <> ""
FTW = WTF
X = X + 1
Loop
End Sub
答案 0 :(得分:1)
行WTF = Cells(X, "F").Value
错误,因为X
为零且行不能为零。此外,循环没有太大的意义,也没有写在任何地方,我想你正在寻找这些方面的东西:
Dim maxX As Integer
maxX = 100 'Max row you want to analyse
Do While X <= maxX
X = X + 1
Cells(X, "F").Value = "whatever"
Loop
也许是这样的:
Dim sourceCol, destCol As String
sourceCol = "A"
destCol = "F"
Do While Cells(X, sourceCol).Value <> ""
X = X + 1
Cells(X, destCol).Value = Cells(X, sourceCol).Value
Loop