循环遍历一系列单元格并更改单元格值的语法 [英] Syntax to loop through a range of cells and change a cell value

查看:59
本文介绍了循环遍历一系列单元格并更改单元格值的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,单元格B2包含一个数字,该数字在使用规划求解生成特定输出时被引用.B2中的不同值会生成不同的值,我正在尝试创建代码来确定哪个值会生成最高的值.

Currently, cell B2 contains a number that gets referenced when using Solver to generate a certain output. Different values in B2 would generate different values, and I am trying to create code that would determine which value would generate the highest value.

代码应使用循环遍历一行包含不同编号的单元格(例如,一行B10:B20),并将每个单元格的值插入B2,然后运行Solver生成输出.

The code should use a loop to go through a row of cells (let's say a row B10:B20) each containing a different number, and for each cell, plug the value into B2, and then run Solver to generate an output.

例如,它应将B2替换为B10,运行求解器,然后将B2替换为B11,再次运行求解器,等等.如何使其不断将B2的值更改为以下单元格?

For example, it should replace B2 with B10, run solver, then replace B2 with B11, run solver again, etc. How do I make it keep changing the value of B2 to the following cell?

推荐答案

dim c as range
for each c in activesheet.range("B10:B20").cells
    activesheet.range("B2").value = c.value
    'etc
next c

这篇关于循环遍历一系列单元格并更改单元格值的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆