XLdown then up 1 !!!

melewie

Board Regular
Joined
Nov 21, 2008
Messages
188
Office Version
  1. 365
Platform
  1. Windows
Hi all,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p></o:p>
I am having trouble with a bit of code. Select the empty cells between to cells.<o:p></o:p>
<o:p></o:p>
Really struggling to do this. Offset moves the whole selection range! I’m guessing it will be something like this<o:p></o:p>
Code:
[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]Range(Selection, Selection.End(xlDown).Row - 1).Select<o:p></o:p>[/FONT][/COLOR]
<o:p></o:p>
<o:p></o:p>
Thanks in advance<o:p></o:p>
<o:p></o:p>
Lewie<o:p></o:p>
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Is selection in the first empty cell or the last cell with a value (before the first empty cell)?

depending on the above,

Either:
Code:
Range(Selection, Selection.End(xlDown).Offset(-1, 0))
Or:
Code:
Range(Selection.Offset(1,0), Selection.End(xlDown).Offset(-1, 0))

-- note that we didn't use .Row at all - using the reference(s) to the cell(s) is handier here.
 
Last edited:
Upvote 0
Cheers xenou,

but offset moves the entire selection up 1. All I want to do is reduce the selection by 1??

Any ideas
 
Upvote 0
So maybe you're talking about resizing your selection?
Code:
Selection.Offset(1, 0).Resize(Selection.Rows.Count - 1).Select
 
Upvote 0
yes thats what im trying to do. Cheers

This code takes one off the top of the selection I need to remove 1 from the bottom???

Any ideas
 
Upvote 0
Resizing the range always happens from the bottom up (and from the right to the left) so I had to add the "Offset(1,0)" part to move the selection down one before taking out the bottom row.

All you need to do is leave out the "Offset(1,0)" part:
Code:
Selection.Resize(Selection.Rows.Count - 1).Select
 
Upvote 0

Forum statistics

Threads
1,215,086
Messages
6,123,033
Members
449,092
Latest member
ikke

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