0

I am dealing with an incredibly large stack of data (close to a 1000 rows). I want to write a function for all of the cells in a column that takes the value from one cell in each row, divides it by the value from another cell in the same row, and writes the result on a third cell in the same row. In other words, as to row X, it takes AX, divides it by BX, and writes it on CX; and as to row Y, it takes the value in AY, divides it by BY, and writes on CY.

As I said, I am dealing with a large stack of data and I really would like to be able to write one function for the entire column, rather than having to write one function for each cell in the column. Conceptually, it is clear to me that I need some way of using the row number as the variable in defining the function and apply that to the entire column. I do not know how to bring that to application though.

4

1 回答 1

0

@pnuts 是绝对正确的,但是,如果你真的想用 VBA 做到这一点,试试这个:

Sub LoopRange()
  Dim rCell As Range
  Dim rRng As Range
  Set rRng = Sheet1.Range("A1:A1000")

  For Each rCell In rRng.Cells
    Range("C" & rCell.Row).Formula = "=A" & rCell.Row & "/B" & rCell.Row
  Next rCell
End Sub

确保您的范围是正确的,否则您将得到除以零的错误。

于 2013-09-19T01:45:46.507 回答