0

我在 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
4

1 回答 1

1

Line WTF = Cells(X, "F").Value is wrong because X is zero and the row cannot be zero. Also the loop does not make too much sense and is not writing anywhere, I guess that you were looking for something on these lines:

   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

Or perhaps something like this:

   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
于 2013-06-27T09:22:00.050 回答