-
10-19-2005, 11:05 PM
#1
Ctrl+End with VBA
How can I use VBA to find out which cell Excel would move to if I pressed
Ctrl+End (i.e. how do I find the last cell in the used range using VBA)?
Thanks.
-
10-19-2005, 11:36 PM
#2
Forum Contributor
By pressing CTRL + End key excel takes you to last used range of your active sheet.
Through vba, try this…
Last edited by ilyaskazi; 10-19-2005 at 11:39 PM.
-
10-20-2005, 12:05 AM
#3
Re: Ctrl+End with VBA
Hi Dave B,
> how do I find the last cell in the used range using VBA)?Try:
Dim rng As Range
Set rng = Cells.SpecialCells(xlCellTypeLastCell)
Note that the last cell in the used range may not be populated.
—
Regards,
Norman«Dave B» <davidbarbetta@hotmail.com> wrote in message
news:%237fwdES1FHA.3376@TK2MSFTNGP14.phx.gbl…
> How can I use VBA to find out which cell Excel would move to if I pressed
> Ctrl+End (i.e. how do I find the last cell in the used range using VBA)?
> Thanks.
>
>
-
10-20-2005, 08:05 AM
#4
Re: Ctrl+End with VBA
I believe this 1-line code should do what you’re looking for.
ActiveCell.SpecialCells(xlLastCell).Select
or as an alternative, this 1 line should work also.
ActiveCell.SpecialCells(xlCellTypeLastCell).Select
-
06-16-2014, 09:41 AM
#5
Registered User
Re: Ctrl+End with VBA
ilyaskazi’s anwer is just fine. Thanks a lot.
The others too. Just replace «.Select» by «.Address» to have the cell.MsgBox (ActiveCell.SpecialCells(xlCellTypeLastCell).Address)
MsgBox (ActiveCell.SpecialCells(xlLastCell).Address)And if you want only the row
MsgBox («La ligne active est : » & ActiveCell.SpecialCells(xlLastCell).Row)
Usefull when you want to make a loop until «end of file».
Содержание
- VBA Editor Keyboard Shortcut Keys List
- Function Keys:
- Ctrl + Function Combination Keys:
- Ctrl + Letter Combination Keys:
- Shift + Function Combination Keys:
- Alt + Function Combination Keys:
- Alt + Letter Combination Shortcut Keys:
- Ctrl + Shift + Function/Key Combination Shortcut Keys:
- Other Shortcut Keys:
- Video Tutorial
- Instructions to Run VBA Macro Code or Procedure:
- Other Useful Resources:
- VBA Excel. Свойство End объекта Range
- Свойство Range.End
- Синтаксис
- Параметры
- Примеры
- Ctrl-End doesn’t bring me to the last cell [closed]
- 2 Answers 2
- VBA Code for «CTRL+HOME/END»?
- Lazarus416
- Excel Facts
- AlphaFrog
- Lazarus416
- AlphaFrog
- Lazarus416
VBA Editor Keyboard Shortcut Keys List
VBA Editor Keyboard Shortcut Keys Complete List helps to fasten process in visual basic editor. These keys works for standard U.S. English keyboards. If it is non U.S. English keyboards the shortcut keys are little different.
Let us how to use keyboard keys as VBA editor shortcut keys.
The following are complete list of VBA editor keyboard shortcut keys list and its performed action.
Function Keys:
Here are the function keys used in the VBA editor window as shortcut keys.
Shortcut Key | Action Performed |
---|---|
F1 | Microsoft Visual Basic for Applications Help/td> |
F2 | Object Browser |
F3 | Find |
F4 | Properties Window |
F5 | Runs the current procedure |
F6 | Split between two code Windows |
F7 | Code window |
F8 | Step into code line by line |
F9 | Breakpoint |
F10 | Activates Menu Bar |
Ctrl + Function Combination Keys:
Here are the Ctrl + Function combination keys which are used in the VBA editor window.
Shortcut Key | Action Performed |
---|---|
Ctrl + F2 | Focus To Object Box |
Ctrl + F4 | Close the active child code Window |
Ctrl + F6 | Go to the next open window |
Ctrl + F8 | Run To Cursor |
Ctrl + F10 | Activate Menu Bar |
Ctrl + Letter Combination Keys:
Here are the Ctrl + Letter combination keys which are used in the VBA editor window.
Shortcut Key | Action Performed |
---|---|
Ctrl + A | Select All Text |
Ctrl + C | Copy |
Ctrl + E | Export Module |
Ctrl + F | Find |
Ctrl + G | Immediate Window |
Ctrl + H | Replace |
Ctrl + I | Turn On Quick Information |
Ctrl + J | List Properties/Methods/Members |
Ctrl + L | Show Call Stack |
Ctrl + M | Import File |
Ctrl + N | New Line |
Ctrl + P | |
Ctrl + R | Project Explorer |
Ctrl + S | Save |
Ctrl + T | Show All Available Available Components |
Ctrl + V | Paste |
Ctrl + X | Cut |
Ctrl + Y | Cut Entire Line |
Ctrl + Z | Undo |
Shift + Function Combination Keys:
Here are the Shift + Function combination keys used in the VBA editor window.
Shortcut Key | Action Performed |
---|---|
Shift + F2 | Procedure Definition |
Shift + F3 | Find Previous |
Shift + F4 | Find Next |
Shift + F8 | Execute Procedure at a time |
Shift + F9 | Quick Watch |
Shift + F10 | Show Right Click Menu |
Alt + Function Combination Keys:
Here are the Alt + Function combination keys used in the VBA editor window.
Shortcut Key | Action Performed |
---|---|
Alt + F4 | Close VBE |
Alt + F5 | Run Error Handler |
Alt + F11 | Toggles between VBE and Application |
Alt + Letter Combination Shortcut Keys:
Here are the Alt + Letter Combination Shortcut Keys used in the VBA editor window.
Shortcut Key | Action Performed |
---|---|
Alt + A | Add-Ins Menu |
Alt + D | Debug Menu |
Alt + E | Edit Menu |
Alt + F | File Menu |
Alt + H | Help Menu |
Alt + I | Insert Menu |
Alt + O | Format Menu |
Alt + Q | Closes the Visual Basic Editor and Return to Application |
Alt + R | Run Menu |
Alt + T | Tools Menu |
Alt + V | View Menu |
Alt + W | Window Menu |
Ctrl + Shift + Function/Key Combination Shortcut Keys:
Here are the Ctrl + Shift + Function/Key combination Shortcut Keys which are used in the VBA editor window.
Shortcut Key | Action Performed |
---|---|
Ctrl + Shift + F2 | Previous/Last Position |
Ctrl + Shift + F8 | Step out of procedure/code |
Ctrl + Shift + F9 | Clear All Breakpoints |
Ctrl + Shift + I | Turn On parameter information |
Ctrl + Shift + J | Displays Available List Constants |
Other Shortcut Keys:
Here are the other Keys which are used in the VBA editor window.
Shortcut Key | Action Performed |
---|---|
Insert | Toggle Insert Mode |
Delete | Deletes right side character of the cursor |
Backspace | Deletes left side character of the cursor |
Tab | Indents the current line |
Enter | New Line |
Home | Moves to the beginning of the current line |
End | Moves to the end of the current line |
Page Up | Moves one screen upwards |
Page Down | Moves one screen downwards |
Left Arrow← | Moves left one character |
Right Arrow→ | Moves right one character |
Up Arrow↑ | Moves up one line |
Down Arrow↓ | Moves down one line |
Ctrl + Home | Moves to the top of the module |
Ctrl + End | Moves to the bottom of the module |
Ctrl + Page Up | Moves to the top of the current procedure |
Ctrl + Page Down | Moves to the start of the next procedure |
Ctrl + Left Arrow | Moves one word to the left |
Ctrl + Right Arrow | Moves one word to the right |
Ctrl + Up Arrow | Moves to the sub or function directly above |
Ctrl + Down Arrow | Moves to the sub or function directly below |
Ctrl + Break | Stops execution |
Ctrl + Insert | Copy selection to Clipboard |
Ctrl + Enter | Enters a New Line/Carriage Return |
Ctrl + Delete | Delete To End Of Word |
Ctrl + Spacebar | Turn On Complete Word |
Ctrl + Backspace | Delete To Start Of Word |
Ctrl + Tab | Moves to the next module |
Shift + Tab | Un-indent the current line |
Shift + Insert | Paste the current clipboard |
Shift + Home | Selects to the start of the line |
Shift + End | Selects to the end of the line |
Shift + Page Up5 | Selects to the top of the module |
Shift + Page Down6 | Selects to the bottom of the module |
Shift + Left Arrow← | Extends the selection one character to the left |
Shift + Right Arrow→ | Extends the selection one character to the right |
Shift + Up Arrow↑ | Extends the selection up one line |
Shift + Down Arrow↓ | Extends the selection down one line |
Ctrl + Shift + F2 | Previous/Last Position |
Ctrl + Shift + F8 | Step out of procedure/code |
Ctrl + Shift + F9 | Clear All Breakpoints |
Ctrl + Shift + I | Turn On parameter information |
Ctrl + Shift + J | Displays Available List Constants |
Alt + Spacebar | Activates System Menu |
Alt + Backspace | Undo the last action |
Alt + Tab | Moves to the next application |
Video Tutorial
You can also watch this tutorial at YouTube.
Instructions to Run VBA Macro Code or Procedure:
You can refer the following link for the step by step instructions.
Other Useful Resources:
Click on the following links of the useful resources. These helps to learn and gain more knowledge.
Источник
VBA Excel. Свойство End объекта Range
Свойство End объекта Range применяется для поиска первых и последних заполненных ячеек в VBA Excel — аналог сочетания клавиш Ctrl+стрелка.
Свойство Range.End
Возвращаемая свойством Range.End ячейка в зависимости от расположения и содержания исходной:
Исходная ячейка | Возвращаемая ячейка |
---|---|
Исходная ячейка пустая | Первая заполненная ячейка или, если в указанном направлении заполненных ячеек нет, последняя ячейка строки или столбца в заданном направлении. |
Исходная ячейка не пустая и не крайняя внутри исходного заполненного диапазона в указанном направлении | Последняя заполненная ячейка исходного заполненного диапазона в указанном направлении |
Исходная ячейка не пустая, но в указанном направлении является крайней внутри исходного заполненного диапазона | Первая заполненная ячейка следующего заполненного диапазона или, если в указанном направлении заполненных ячеек нет, последняя ячейка строки или столбца в заданном направлении. |
Синтаксис
Expression — выражение (переменная), представляющее объект Range .
Параметры
Параметр | Описание |
---|---|
Direction | Константа из коллекции XlDirection , задающая направление перемещения. Обязательный параметр. |
Константа | Значение | Направление |
---|---|---|
xlDown | -4121 | Вниз |
xlToLeft | -4159 | Влево |
xlToRight | -4161 | Вправо |
xlUp | -4162 | Вверх |
Примеры
Скриншот области рабочего листа для визуализации примеров применения свойства Range.End :
Примеры возвращаемых ячеек свойством End объекта Range(«C10») с разными значениями параметра Direction:
Выражение с Range.End | Возвращенная ячейка |
---|---|
Set myRange = Range(«C10»).End(xlDown) | Range(«C16») |
Set myRange = Range(«C10»).End(xlToLeft) | Range(«A10») |
Set myRange = Range(«C10»).End(xlToRight) | Range(«E10») |
Set myRange = Range(«C10»).End(xlUp) | Range(«C4») |
Пример возвращения заполненной значениями части столбца:
Источник
Ctrl-End doesn’t bring me to the last cell [closed]
Want to improve this question? Update the question so it’s on-topic for Stack Overflow.
Closed 9 years ago .
Ctrl-end key is supposed to bring me to the bottom, right-most cell. However, on several cases, it goes beyond that, meaning it goes hundreds of cells down, even if there are actually no data on those cells.
Can you advise a VBA script on how to clean-up those possibly invisible data that causes this? I’m pretty sure it doesn’t work with a regular delete as despite doing that, it still behaves the same way.
2 Answers 2
Ctrl-End does take you to the bottom-right cell, it just uses different rules to what you’d expect in deciding what that cell should be. Just about any cell that’s been referenced in any way will be included in the decision. It’s annoying, but that’s how Excel «works».
- Select the last cell that contains data in the worksheet
To delete any unused rows:
- Move down one row from the last cell with data.
- Hold the Ctrl and Shift keys, and press the Down Arrow key
- Right-click in the selected cells, and, from the shortcut menu, choose Delete
- Select Entire Row, click OK.
delete entire row
To delete any unused columns:
- Move right one column from the last cell with data.
- Hold the Ctrl and Shift keys, and press the Right Arrow key
- Right-click in the selected cells, and, from the shortcut menu, choose Delete
- Select Entire Column, click OK.
Save the file. Note: In older versions of Excel, you may have to Save, then close and re-open the file before the used range is reset.
Источник
VBA Code for «CTRL+HOME/END»?
Lazarus416
Board Regular
Is there a VBA code that I can use to mimic the ctrl+home/end function? When I record a macro manually and use those functions, it inserts code to select a specific cell rather than code to «goto the 1st cell» or «goto the last cell». Thanks in advance for any info.
Excel Facts
AlphaFrog
MrExcel MVP
I think Ctrl+Home always moves to cell A1 assuming it’s visible. If A1 is not visible, then this moves to the 1st visible cell.
Cells.SpecialCells(xlCellTypeVisible)(1).Select
This is equivalent to Ctrl+End
Cells.SpecialCells(xlCellTypeLastCell).Select
Lazarus416
Board Regular
Appreciate it. I’ll give that one a try.
Oh. one more related question, is there a VBA equivalent to ctrl+shift+end? As I sit here and think about it, that’s really the one I need. For selecting all of the (variable sized) worksheet so that I can covert it to a table as part of the macro.
AlphaFrog
MrExcel MVP
This selects contiguous data starting from A1
Range(«A1»).CurrentRegion.Select
Or this.
Range(«A1», Cells.SpecialCells(xlCellTypeLastCell)).Select
Lazarus416
Board Regular
This selects contiguous data starting from A1
Range(«A1»).CurrentRegion.Select
Or this.
Range(«A1», Cells.SpecialCells(xlCellTypeLastCell)).Select
Thanks Alpha, the first one worked great (once I figured out how to stick in the table conversion code). You just made my life MUCH easier.
For anyone who needs the full conversion code to convert a dynamic range into a table, here it is:
Источник
How do I adjust the below code to work with the equivalent of crtl shift end in VBA (which I think is xlLastCell or xlCellTypeLastCell)?
My sheet has 64 columns I only want to select Column 1 to 58 where I have data starting on row 2. The below works unless the sheet is blank and then all rows from row 2 to 1048575 are selected. Because I have protected cells below row 200,000 my script errors with the below.
With Worksheet(WorkSheet)
.Range(.Cells(2,1).End(XlDown),.Cells(2,58)).Select
End With
Selection.ClearContents
asked Oct 30, 2017 at 17:48
2
Start at row 200,000 and look up.
With Worksheet(WorkSheet)
.Range(.Cells(200000, "A").End(XlUP), .Cells(2, "BF")).ClearContents
End With
'possible alternate to avoid clearing row 1
With Worksheet(WorkSheet)
.Range(.Cells(200000, "A").End(XlUP).offset(1, 0), .Cells(2, "BF")).ClearContents
End With
answered Oct 30, 2017 at 17:53
2
Do you spend a lot of time programming in Visual Basic for Applications (VBA) in Microsoft Excel?
If you want to work more efficiently, then learning keyboard shortcuts is the way to go. Keyboard shortcuts can help you save time and effort when coding in VBA for Excel.
You can learn how to do many actions in VBA for Excel with the press of a few keys. You’ll be able to work faster and smarter than ever before to build your macros when you use these keyboard shortcuts!
Check out our full list of VBA keyboard shortcuts today and start working like a pro!
Be sure to check out the complete list of keyboard shortcuts in Microsoft Excel for more great keyboard shortcuts!
Visual Basic Keyboard Shortcuts
Up
Move the cursor up one line.
Down
Move the cursor down one line.
Left
Move the cursor one character to the left.
Right
Move the cursor one character to the right.
Page Up
Move the viewable area of the module up one page.
Page Down
Move the viewable area of the module down one page.
Tab
Add one level of indentation to a highlighted block of code.
Insert
Toggle insert mode on or off.
Home
Move the cursor to the beginning of the current line.
End
Move the cursor to the end of the current line.
Back Space
Deletes one character to the left of the cursor.
Delete
Deletes one character to the right of the cursor.
F1
Open visual basic editor help.
F2
Open the visual basic object browser.
F3
Perform the Find Next command.
F4
Open the Properies window.
F5
Run the current procedure.
F6
Move the cursor between split windows.
F8
Step into code
Equivalent to Debug > Step Into.
F9
Toggle code breakpoints on or off
Equivalent to Debug > Toggle Breakpoint.
F10
Activate focus on the menu bar. Select different menu headings with left or right keys and open a menu with the down key.
Alt + A
Open the Add-Ins menu.
Alt + D
Open the Debug menu.
Alt + E
Open the Edit menu.
Alt + F
Open the File menu.
Alt + H
Open the Help menu.
Alt + J
Open the Insert menu.
Alt + O
Open the Format menu.
Alt + Q
Close the visual basic editor.
Alt + R
Open the Run menu.
Alt + T
Open the Tools menu.
Alt + V
Open the View menu.
Alt + W
Open the Window menu.
Alt + F4
Close the visual basic editor.
Alt + F5
Run Error Handler.
Alt + F6
Switch Between Last 2 Windows.
Alt + F7
Step Error Handler.
Alt + F11
Switch between the visual basic editor and Excel.
Alt + Tab
Cycle through all open Windows applications.
Alt + Space Bar
Open visual basic editor system menu.
Alt + Back Space
Undo the last command.
Ctrl + A
Select all text in the current module.
Ctrl + C
Copy the current selection.
Ctrl + E
Export the currently selected module.
Ctrl + F
Open the Find dialog box.
Ctrl + G
Open the Immediate window.
Ctrl + H
Open the Replace dialog box.
Ctrl + I
Display Quick Info for object selected.
Ctrl + J
Show a list of available properties or methods
Equivalent to Edit > List Properties/Methods.
Ctrl + J
Bring object to front when creating a user form.
Ctrl + K
Send object to back when creating a user form.
Ctrl + L
Equivalent to View > Call Stack.
Ctrl + M
Import a module file
Equivalent to File > Import File….
Ctrl + N
Create a new line.
Ctrl + P
Open the Print VBAProject dialog box.
Ctrl + R
Open the Project window.
Ctrl + S
Save the current project.
Ctrl + T
Open the Components dialog box.
Ctrl + V
Paste the last item copied to your clipboard.
Ctrl + W
Equivalent to Debug > Edit Watch.
Ctrl + X
Cut the current selection.
Ctrl + Y
Cut the entire current line.
Ctrl + Z
Undo the last command.
Ctrl + F2
Activate focus to the object selection drop down.
Ctrl + F4
Close current window.
Ctrl + F8
Equivalent to Debug > Run To Cursor.
Ctrl + F9
Equivalent to Debug > Set Next Statement.
Ctrl + F10
Activate focus on the menu bar. Select different menu headings with left or right keys and open a menu with the down key.
Ctrl + Tab
Cycle through all open visual basic windows.
Ctrl + Space Bar
Auto complete current word.
Ctrl + Back Space
Delete one word to the left of the cursor.
Ctrl + Insert
Copy the current selection.
Ctrl + Delete
Delete one word to the right of the cursor.
Ctrl + Home
Move the cursor to the start of the current module.
Ctrl + End
Move the cursor to the end of the current module.
Ctrl + Page Up
Move the cursor to the start of the current procedure.
Ctrl + Page Down
Move the cursor to the end of the current procedure.
Ctrl + Up
Move the cursor to the previous procedure.
Ctrl + Down
Move the cursor to the next procedure.
Ctrl + Left
Move the cursor to the left by one word.
Ctrl + Right
Move the cursor to the right by one word.
Shift + F2
Go to variable declaration or object definition.
Shift + F3
Find previous item from the cursor for the last item searched.
Shift + F4
Find next item from the cursor for the last item searched.
Shift + F8
Equivalent to Debug > Step Over.
Shift + F9
Equivalent to Debug > Quick Watch.
Shift + F10
Equivalent to right click to show menu.
Shift + Tab
Remove one level of indentation from a highlighted block of code.
Shift + Insert
Paste the last item copied to your clipboard.
Shift + Home
Select from the cursor to the start of the current line.
Shift + End
Select from the cursor to the end of the current line.
Shift + Page Up
Select from the cursor to the top of the module.
Shift + Page Down
Select from the cursor to the bottom of the module.
Shift + Up
Extend the current selection up one line.
Shift + Down
Extend the current selection down one line.
Shift + Left
Extend the current selection to the left by one character.
Shift + Right
Extend the current selection to the left by one character.
Ctrl + Shift + I
Equivalent to Edit > Parameter Info.
Ctrl + Shift + J
Equivalent to Edit > List Constants.
Ctrl + Shift + F2
Move the cursor to its previous position.
Ctrl + Shift + F8
Equivalent to Debug > Step Out.
Ctrl + Shift + F9
Equivalent to Debug > Clear All Breakpoints.
About the Author
John is a Microsoft MVP and qualified actuary with over 15 years of experience. He has worked in a variety of industries, including insurance, ad tech, and most recently Power Platform consulting. He is a keen problem solver and has a passion for using technology to make businesses more efficient.
-
#2
I think Ctrl+Home always moves to cell A1 assuming it’s visible. If A1 is not visible, then this moves to the 1st visible cell.
Cells.SpecialCells(xlCellTypeVisible)(1).Select
This is equivalent to Ctrl+End
Cells.SpecialCells(xlCellTypeLastCell).Select
Last edited: Feb 26, 2016
-
#3
Appreciate it. I’ll give that one a try.
Oh…one more related question, is there a VBA equivalent to ctrl+shift+end? As I sit here and think about it, that’s really the one I need. For selecting all of the (variable sized) worksheet so that I can covert it to a table as part of the macro.
Last edited: Feb 26, 2016
-
#4
This selects contiguous data starting from A1
Range(«A1»).CurrentRegion.Select
Or this…
Range(«A1», Cells.SpecialCells(xlCellTypeLastCell)).Select
-
#5
This selects contiguous data starting from A1
Range(«A1»).CurrentRegion.SelectOr this…
Range(«A1», Cells.SpecialCells(xlCellTypeLastCell)).Select
Thanks Alpha, the first one worked great (once I figured out how to stick in the table conversion code). You just made my life MUCH easier.
For anyone who needs the full conversion code to convert a dynamic range into a table, here it is:
Code:
ActiveSheet.ListObjects.Add(xlSrcRange, Range("A1").CurrentRegion, , xlYes).Name = _
"Table1"
Range("Table1[#All]").Select
ActiveSheet.ListObjects("Table1").TableStyle = "TableStyleMedium16"
(The tablestyle can be whatever you want…)