Excel VBA将多个单元格设置为相同的值 [英] Excel VBA set multiple cells to the same value

查看:594
本文介绍了Excel VBA将多个单元格设置为相同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个工作表上的每个第八个单元格设置为另一工作表中一个单元格的值.我在这里写的:

I want to set every eighth cell on one worksheet to the value of a cell in another worksheet. I wrote this here:

Sub xx()
    For i = 5 To 45 Step 8
        Set ThisWorkbook.Sheets("Sheet5").Cells(i, 3).Value = ThisWorkbook.Sheets("Sheet7").Cells(13, 31).Value
    Next i
End Sub

如果我尝试运行它,它将给我下标超出范围的错误. Sheet5 也被命名为 Binomial Sheet ,我是否必须对此进行不同的引用? 还有其他方法可以做到这一点吗?

If I try to run it, it gives me a subscript out of range error. Sheet5 has also been named Binomial Sheet, do I have to reference this differently? Are there other ways to accomplish this?

推荐答案

尚未提及为多个单元格设置相同值的选项:

This option of setting the same value for several cells was not yet mentioned:

ActiveSheet.Range("A1,B2,C3:D4").Value = "SomeValue"

这篇关于Excel VBA将多个单元格设置为相同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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