Excel宏单元格地址增加 [英] Excel macro cell address increase
问题描述
我正在执行excel单元格颜色匹配功能。
示例:
当我将单元格A1更改为红色时,单元格D1将变为红色。
如果将C1改为红色,F1将变为红色。所有需要增加3列。
现在我只需要修改c.Address+ 3,这样单元格就可以做D1了。
我尝试使用c.Address + 3但它不能工作。
任何帮助将会欣赏!
谢谢!
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
对于每个c在工作表(Sheet1)。范围(A1:C1)。单元格
如果c。 Interior.Color = 255 Then
Sheet1.Range(c.Address + 3).Interior.Color = 255<< - 无法正常工作
Else
Sheet1 .Range(c.Address + 3).Interior.Color = white<< - 无法正常工作
结束如果
下一步c
End Sub
更改:
Sheet1.Range(c.Address + 3)
到这个
Sheet1.Range(c.Address).offset(0,3 )
虽然我不知道你为什么需要 Sheet1.Range(c 。地址)
而不只是c,是ca范围?如果是这样,你可以做 c.offset(0,3)
Can i increase the cell address by using macro? I'm implementing excel cell color matching function.
Example: When i change the cell "A1" to red, cell "D1" will change to red. if change "C1" to red, "F1" will change to red too. All need to increase 3 column.
Now i just need to modify the "c.Address" by + 3 so the cell will go do D1. I try using c.Address + 3 but it can't work. Any help will be appreciate!
Thanks!
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
For Each c In Worksheets("Sheet1").Range("A1:C1").Cells
If c.Interior.Color = 255 Then
Sheet1.Range(c.Address + 3 ).Interior.Color = 255 <<-- Can't work
Else
Sheet1.Range(c.Address + 3 ).Interior.Color = white <<-- Can't work
End If
Next c
End Sub
Change this:
Sheet1.Range(c.Address + 3 )
To this
Sheet1.Range(c.Address).offset(0,3)
Although I don't know why you need Sheet1.Range(c.Address)
and not just c, is c a range? if so you can just do c.offset(0,3)
这篇关于Excel宏单元格地址增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!