Search code examples
vbaexcelvariablesoffset

Variable with Offset function to create a range


I am trying to use a variable alongside the offset function to create a range which I can then utilise.

I have the below code however this errors on the last line.

Dim rng As Range
Dim targetrow As Range
targetrow = ActiveSheet.Range("Total").Offset(-2, 0).Row
rng = Range(Cells((targetrow), 7), Cells(10, 7))

Any help would be much appreciated

Thanks


Solution

  • You need to use Set with object variables:

    Set rng = Range(Cells((targetrow), 7), Cells(10, 7))