Go to row under selected region?

LoriD

Board Regular
Joined
Apr 1, 2002
Messages
148
In a macro, I need to go the first row under the Current region, and insert totals. Is there quick way to do this? (At least the part about going to the row under the selected current region)
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Hi,

This should get you started

'------
Sub test()
Dim x

x = Selection.Row + Selection.Rows.Count
Rows(x).Select

End Sub
'------

Bye,
Jay
 
Upvote 0
Thanks, Jay.

Any chance you could walk me through what exactly this code says?

Lori
 
Upvote 0
On 2002-05-09 11:32, LoriD wrote:
Thanks, Jay.

Any chance you could walk me through what exactly this code says?

Lori

Hi Lori,

In the routine, I assumed that you had selected your range on the worksheet prior to running. If this is not the case, that can easily be amended.

So, whatever you selected is understood in the code as the Selection (automatically known by Excel).

Try this to see.

Sub test2()
MsgBox Selection.Address
MsgBox Selection.Address(False, False)
End Sub


Now suppose you chose the range A1:B6, you have 6 rows of data, right? What about A5:C10? The same number of rows of data, only starting at a different row.

MsgBox Selection.Rows.Count
and its counterpart
MsgBox Selection.Columns.Count

will tell you how many rows/columns is contained within the selection.
(I am assuming only one range is selected).

Now, if you have 6 rows of data, the row below that is the row you want, but where does the first row start?

Selection.Row will tell you the starting row of the data, no matter how many rows are used or wherever the range begins.

Range("A5:A125").Row = 5
Range("A5:IV65536").Row = 5, also

Range("A100:A125").Row = 100

So putting it together, with A5:B10 as a sample

Selection.Row gives the first row in the range = 5

Selection.Rows.Count gives the number of rows spanned by your selection = 6

x = 5 + 6 = 11 and that is the next available row.

You can definitely get there using numerous other ways, too. This was only one option available.

HTH,
Jay
 
Upvote 0
Thank you for the explanation. I get the concepts, but I usually need it explained in English first! Thank you for your time and patience.
 
Upvote 0
So, if x = rows counted, does y = columns counted? (If I only wanted to select the cells under my range?)
 
Upvote 0
On 2002-05-09 12:26, LoriD wrote:
So, if x = rows counted, does y = columns counted? (If I only wanted to select the cells under my range?)

No. I only used x for illustration. You have to set your variable

I could easily have used

ROW_I_AM_TRYING_TO_FIND = .....

You can use y, but you would have to tell it it's value

y = Selection.Column + Selection.Columns.Count

would find the column 1 to the right of your selection.

Bye,
Jay
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,449
Members
448,966
Latest member
DannyC96

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