是否可以在Rg中引用Rg

时间:2021-09-11 02:27:48

Is it possible to refer to Rg in With Rg? I have a long with statement and I would like to pass the range specified in the With statement as a parameter. Is this possible?

是否有可能在Rg中引用Rg?我有一个long with语句,我想将With语句中指定的范围作为参数传递。这可能吗?

With rg.OffSet(0, -1).Resize(ColumnSize:=1)

    'set conditional format
    Call SetConditionalFormat(rg.OffSet(0, -1).Resize(ColumnSize:=1))

    'I tried this but it didn't work
    Call SetConditionalFormat(.range)

End With

Sure I could simply repeat the rg.OffSet(0, -1).Resize(ColumnSize:=1) or assign it to a variable, but I'm curious if such a thing exists as referring to itself.

当然我可以简单地重复rg.OffSet(0,-1).Resize(ColumnSize:= 1)或将其分配给一个变量,但我很好奇是否存在这样的事物来引用它自己。

2 个解决方案

#1


1  

In case with Range object you could use:

如果是Range对象,您可以使用:

Call SetConditionalFormat(.Cells)

it's not a self-referring, but could help you to operate with target object.

它不是一个自我引用,但可以帮助你操作目标对象。

#2


0  

I have seen prettier code but it works ;)

我见过更漂亮的代码,但它有效;)

With rg.Offset(0, -1).Resize(ColumnSize:=1)

    Call SetConditionalFormat(.Parent.Range(.Address))

End With

#1


1  

In case with Range object you could use:

如果是Range对象,您可以使用:

Call SetConditionalFormat(.Cells)

it's not a self-referring, but could help you to operate with target object.

它不是一个自我引用,但可以帮助你操作目标对象。

#2


0  

I have seen prettier code but it works ;)

我见过更漂亮的代码,但它有效;)

With rg.Offset(0, -1).Resize(ColumnSize:=1)

    Call SetConditionalFormat(.Parent.Range(.Address))

End With