I'm trying to find the used range from a selected cell to the End of the worksheet.
In this case, starting from Cell "J4".
The solution below does start at J4 but when it comes to the End, it looks at the whole sheet.
In the attached snapshot, I want to select range "J4:W13", not "J4:W20".
In this case, starting from Cell "J4".
The solution below does start at J4 but when it comes to the End, it looks at the whole sheet.
In the attached snapshot, I want to select range "J4:W13", not "J4:W20".
VBA Code:
Sub DynamicRange()
Dim sht As Worksheet
Dim LastRow As Long, LastColumn As Long
Dim StartCell As Range
Set sht = Worksheets("Sections")
Set StartCell = Range("J4")
Worksheets("Sections").UsedRange
LastRow = StartCell.SpecialCells(xlCellTypeLastCell).Row
LastColumn = StartCell.SpecialCells(xlCellTypeLastCell).Column
sht.Range(StartCell, sht.Cells(LastRow, LastColumn)).Select
End Sub