Can I link to Rg in With Rg

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

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

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

+4
source share
2 answers

In the case of an object, Rangeyou can use:

Call SetConditionalFormat(.Cells)

this is not self-awareness, but can help you work with the target.

+1
source

I saw more beautiful code, but it works;)

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

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

End With
0
source

Source: https://habr.com/ru/post/1523595/


All Articles