Background: I have a function which takes a couple of ranges as inputs and does some calculations. It is widely used, so I am keen to avoid changing it if possible.
However I now need to use the same function but with one of the ranges I need to have it operate on the negative equivalent of the range.
My question is: Is there an easy way to operate on a copy of a range? (without changing the underlying source data in the spreadsheet - I can't go turning all the values negative there, it is just needed in the calculation).
I tried writing a simply function (below). I don't know if I'm thinking of VBA ranges in the wrong way, but whenever I assign it the affects get reflected on the source (i.e. it's doing it in a By Reference manner rather than By Value, if that makes sense in this context)
Function NegateRangeContents(rRange As Range) As Range
Dim r As Range
Dim rOutput As Range
Set rOutput = rRange
For Each r In rOutput
r.Value = -r.Value
Next r
Set NegateRangeContents = rOutput
Set r = Nothing
Set rOutput = Nothing
End Function
I did try Googling for an answer and looked for similar questions on here.
Maybe I'm missing something obvious and just need more coffee?! Any advice gratefully accepted!