0
Set dr = Range(Selection, Cells(Rows.Count, Selection.Column).End(xlUp)(xlToRight))

Basically, I want to select a whole range spanning across numerous rows and columns with data being populated interspersed

It works perfectly upto Xlup. But when I add Xltoright, it doesn't take effect.

enter image description here

Kostas K.
  • 8,293
  • 2
  • 22
  • 28
Gowtham
  • 3
  • 3

1 Answers1

0

If you are trying to go right and down of current selection then consider the following code.

As you later attempt to select in sheet 1 I am going to assume you actually meant Worksheet("Sheet1").

If that is the case you can more safely do the following:

Sub hi()

    Dim dr As Range

    With ThisWorkbook.Worksheets("Sheet1")

        Set dr = .Range(Selection, .Cells(.Rows.Count, Selection.Column).End(xlUp).End(xlToRight))

    End With

    Debug.Print dr.Address

End Sub

Note:

Bear in mind that Cells /Range without a qualifying Worksheet will use the Activesheet. See the excellent discussion here:

Is the . in .Range necessary when defined by .Cells?.

Synopsis:

With "." is faster, avoids potential for error 1004 and is generally considered best practice.

QHarr
  • 83,427
  • 12
  • 54
  • 101