CTRL + Shift + Down in a Macro?!!?

senker

New Member
Joined
Aug 19, 2015
Messages
4
This is the one that it seems how many forums or formulas I try I can't figure out!

I always have various ranges that, it could be 1 row down or it can be 100, how do I make the macro figure out far to go?
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
You could create dynamic ranges, or determine the last row and column using:

Code:
LastRow = Cells(Rows.Count,1).End(xlUp).Row
LastCol = Cells(1,Columns.Count).End(xlToLeft).Column
 
Upvote 0
Neil's solution will work for finding the last row where column A is used in the workbook. If you want the exact behavior of Ctrl+Shift+Down, use xlDown instead of xlUp:
Code:
Dim cl As Range
Set cl = ActiveCell
Range(cl, cl.End(xlDown)).Select

Like Ctrl+Shift+Down, if you are on the last entry of a column it will take you all the way to the bottom of the worksheet, so watch out for that.

-Amy Galick
 
Upvote 0
thanks for the replys but still no luck:

I have various ranges, could be as short as 2 rows or as long as 50+

Code I have:

Code:
Sub q()
'
' q Macro
'
' Keyboard Shortcut: Ctrl+q
'
    ActiveCell.Range("A1:AD1").Select
    Selection.Copy
    Range(Selection, Selection.End(xlDown)).Select
    ActiveCell.Range("A1:AD12").Select
    ActiveSheet.Paste
    Selection.End(xlDown).Select
End Sub
 
Upvote 0
What are you trying to do with this Sub? Right now the line corresponding to Ctrl+Shift+Down is not really doing anything, because in the very next line you select something different.

Code:
Sub q()
'
' q Macro
'
' Keyboard Shortcut: Ctrl+q
'
    ActiveCell.Range("A1:AD1").Select 'expand the selection to the right so that it has 30 columns and 1 row
    Selection.Copy
    Range(Selection, Selection.End(xlDown)).Select 'select more rows as if you had pushed ctrl+shift+down
    ActiveCell.Range("A1:AD12").Select 'select 30 columns and 12 rows
    ActiveSheet.Paste 'paste the 1x30 copied range into the 12x30 selected range -- repeating the data in each row
    Selection.End(xlDown).Select 'select the last (probably 12th) cell in the column where you started
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,831
Messages
6,127,148
Members
449,364
Latest member
AlienSx

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