基本VBA分两栏
Basic VBA to divide two columns
我是 VBA 的新手,也是 Whosebug 的新手,我只是想按照教程来掌握窍门。
如果我有两列数字,A 列和 B 列,我想除以 A/B 并将结果放入 C。我想使用 for 循环来这样做。到目前为止我的代码是:
Sub ForLooptoDivide()
Dim i As Integer
For i = 2 To 6
Cells(i, 3).Value = Cells(1, i).Value / Cells(2, i).Value
Next i
End Sub
正如我所说,我是全新的,刚刚遇到了教程障碍。
谢谢!
你没有提到你的问题。有很多方法可以做到这一点。下面的 sub 将在 Column A
中找到最后使用的单元格,然后迭代将 Column A
除以 Column B
并将结果放入 Column C
。试试吧...
Sub DivideColumns()
Dim Lastrow As Long
Dim i As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To Lastrow
Cells(i, "C") = Cells(i, "A") / Cells(i, "B")
Next i
End Sub
我是 VBA 的新手,也是 Whosebug 的新手,我只是想按照教程来掌握窍门。 如果我有两列数字,A 列和 B 列,我想除以 A/B 并将结果放入 C。我想使用 for 循环来这样做。到目前为止我的代码是:
Sub ForLooptoDivide()
Dim i As Integer
For i = 2 To 6
Cells(i, 3).Value = Cells(1, i).Value / Cells(2, i).Value
Next i
End Sub
正如我所说,我是全新的,刚刚遇到了教程障碍。
谢谢!
你没有提到你的问题。有很多方法可以做到这一点。下面的 sub 将在 Column A
中找到最后使用的单元格,然后迭代将 Column A
除以 Column B
并将结果放入 Column C
。试试吧...
Sub DivideColumns()
Dim Lastrow As Long
Dim i As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To Lastrow
Cells(i, "C") = Cells(i, "A") / Cells(i, "B")
Next i
End Sub