Of the things you have allegedly tried...
Range(RValue, Cells(RValue.Row, LastColumn).Column)
gives a Type Mismatch error, assuming that
LastColumn
is a range
Range(RValue:cells(RValue,LastCol))
just gives a compile error because of the colon :
If you want to include a colon in a range definition then use it within a string e.g.
Dim x As Range
Set x = Range(RValue.Address & ":" & LastColumn.Address)
You are actually in the right space with
Range(RValue, Cells(RValue.Row, LastColumn.Column))
What makes you think that it doesn't work?
Sub demo()
Dim RValue As Range
Set RValue = ThisWorkbook.Sheets(1).Range("A7")
Dim LastColumn As Range
Set LastColumn = ThisWorkbook.Sheets(1).Range("E1")
ThisWorkbook.Sheets(1).Range(RValue, ThisWorkbook.Sheets(1).Cells(RValue.Row, LastColumn.Column)).Value = RValue.Value
End Sub
Alternatively you could have used OffSet
ThisWorkbook.Sheets(1).Range(RValue, RValue.Offset(0, LastColumn.Column - 1)).Value = RValue.Value
I will also repeat my advice about being explicit about ranges - don't just use
Range
, that applies to the Active sheet in the Active workbook - and that can easily change with a single click of the mouse - Users
will do that. Be explicit - state which Workbook, and which Sheet, or use
With
e.g.(Note the periods before Range and Cells!!)
With ThisWorkbook.Sheets(1)
.Range(RValue, .Cells(RValue.Row, LastColumn.Column)).Value = RValue.Value
End With