trying to set a range from RValue to RValue row till last column in that row. I have tried the code below but have been struggling to get any of them to work.
Range(RValue, Cells(RValue.Row, LastColumn.Column))
'or
Range(RValue, Cells(RValue.Row, LastColumn).Column)
'or
Range(RValue:cells(RValue,LastCol))
CodePudding user response:
This is a compressed solution that can error when using on an empty row:
Set r = Range(RValue, Cells(RValue.Row, Cells(RValue.Row, Columns.Count).End(xlToLeft).Column))
Debug.Print RValue.Address
And this is a more complex but robust solution:
Dim RValue As Range, iCol As Long
iCol = Cells(RValue.Row, Columns.Count).End(xlToLeft).Column - RValue.Column 1
If iCol < 1 Then iCol = 1
Set RValue = RValue.Resize(1, iCol)
Debug.Print RValue.Address