Dynamic range - from specified cell to End

Formula11

Active Member
Joined
Mar 1, 2005
Messages
433
Office Version
  1. 365
Platform
  1. Windows
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".

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
 

Attachments

  • Range2.png
    Range2.png
    26.4 KB · Views: 14

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
it kinda sounds like you need a literal representation of a range area. either that or a named range,
 
Upvote 0
This should get the last row based on your example
VBA Code:
LastRow = Range("J4").CurrentRegion.Rows(Range("J4").CurrentRegion.Rows.Count).Row

Implementing within your code example:

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.CurrentRegion.Rows(StartCell.CurrentRegion.Rows.Count).Row
    LastColumn = StartCell.SpecialCells(xlCellTypeLastCell).Column
    sht.Range(StartCell, sht.Cells(LastRow, LastColumn)).Select
End Sub
 
Upvote 0
Depending on what's in your cells try
VBA Code:
Range("J4").CurrentRegion.Select
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,042
Members
449,063
Latest member
ak94

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top