【问题标题】:Coding while loops in VBA to copy and paste value that ends the loop在 VBA 中编码 while 循环以复制和粘贴结束循环的值
【发布时间】:2018-05-18 18:28:16
【问题描述】:

我有两列数据要比较,然后从单元格中提取一个小于右侧单元格的值。

如果 A 小于 B,则将 A 列的值复制并粘贴到 C1。我知道 while 循环可以帮助检查,但我不确定如何停止它检查,然后从 A 列中的单元格中获取值并将其粘贴到新单元格中。

例如: A 列 1.00、1.50、1.75、1.95、2.00、2.1
B 列 0.50、1.00、1.50、2.00、2.50、3.00
C 列 1.95

【问题讨论】:

  • "IF A" 是您能告诉我们的全部吗?
  • 您可以添加更多细节,包括代码。请在此处查看如何提出好的问题:stackoverflow.com/help/how-to-ask

标签: excel loops vba


【解决方案1】:

1) 使用 for 循环遍历行
2) 满足条件时使用Exit For退出循环

 For intRow = 1 to 6
     if Cells(intRow, 1).value < Cells(intRow, 2).value Then
         Range("C1").value = Cells(intRow, 1).value
         Exit For
     End If
 Next intRow

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-20
    • 2019-01-23
    • 2015-12-02
    • 1970-01-01
    • 2020-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多