Macro to select a range using last row and column?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

I just need a macro to select the following range for me

Sheet(Data1).Range A6: Last row (calculated from column a) and Last Column (Calculated from Row 6

Please help if you can

Thanks

Tony
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Maybe...

Code:
Dim lr As Long, lc As Long
Dim myRange As Range

With Sheets("Data1")
    'Get last row
    lr = .Cells(.Rows.Count, "A").End(xlUp).Row
    'Get last column
    lc = .Cells(6, .Columns.Count).End(xlToLeft).Column
    'Set data range
    Set myRange = Range(.Cells(6, "A"), .Cells(lr, lc))
End With

M.
 
Upvote 0
Beaten 2it
 
Last edited:
Upvote 0
tonywatsonhelp,

Try the following macro.


Code:
Sub tonywatsonhelp()
' hiker95, 04/24/2018, ME1052941
Dim lr As Long, lc As Long
With Sheets("Data1")
  lr = .Range("A6").CurrentRegion.Rows.Count
  lc = .Cells(6, Columns.Count).End(xlToLeft).Column
  .Range("A6").Resize(lr, lc).Select
End With
End Sub
 
Upvote 0
THank you
Marcelo, this is great,
Fluff always appreciate your help so thanks
and Hiker great alternative thank you

Tony
 
Upvote 0
tonywatsonhelp,

Thanks for the feedback.

You are very welcome. Glad we could help.

And, come back anytime.
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,530
Members
448,969
Latest member
mirek8991

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