double xlDown

DonAndress

Active Member
Joined
Sep 25, 2011
Messages
362
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hello.

Today I need to define a range more or less like below:

Worksheets("sheet").Range("M1:Q54")

Now.
Rows 1, 2 and 3 are merged but the rest below is not.
Three first rows contain text and the rest multiple velues (but it's a series).

I don't know if cell Q54 is the last one so I need to use xlDown (Q is the last column).

When I try to use on a keyboard "ctrl+shift+down_arrow" it seems that Excel treats these cells as different type and makes me press the combination twice to select whole range M1:Q54.


How should the code look like so it lets to select different ranges down?
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Take a look at this...just set this equal to a variable and then do Worksheets("sheet").Range("M1:Q" & LastRow)
I'm not entirely sure if it's Range("M1:Q" & LastRow) or Range("M1:Q" LastRow)
http://www.mrexcel.com/td0058.html

Update: I prefer this method listed on the website: LastRow = ActiveSheet.UsedRange.Rows.Count

-Austin
 
Upvote 0
But how do I define this "UsedRange" part?
The table I'm trying to find the last row of is not the only one in the sheet. Other tables have different amount of rows.
 
Upvote 0
If you want to find the last row of data don't use UsedRange, it can give incorrect results - I just tried it with a worksheet with only 7 rows, the row count of the worksheet's UsedRange was 115 - I think that might be a bit out.:)

There are various other methods, here's a couple:
Code:
LastRow = Worksheets("sheet").Range("Q" & Rows.Count).End(xlUp).Row
Code:
LastRow = Worksheets("sheet").Cells.Find("*",SearchOrder:=xlByRows,SearchDirection:=xlPrevious).Row
 
Upvote 0
If you want to find the last row of data don't use UsedRange, it can give incorrect results - I just tried it with a worksheet with only 7 rows, the row count of the worksheet's UsedRange was 115 - I think that might be a bit out.:)

Good to know, thanks for the heads up!
 
Upvote 0

Forum statistics

Threads
1,207,013
Messages
6,076,149
Members
446,187
Latest member
LMill

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