Excel

Apply carriage-return & line-feed on your worksheet

Ease of Use

Easy

Version tested with

2000 

Submitted by:

johnske

Description:

When making entries on the worksheet, when the last relevant entry has been made the first cell for the next row is automatically selected. 

Discussion:

When there are many columns of data to be entered it can be a slow (and error-prone) process to scoll back and select the first cell for the next row to be entered. This does that quickly and without error. In addition, to speed things up even further, when the sheet is activated, the first cell in the next empty row is automatically selected. 

Code:

instructions for use

			

Option Explicit 'Note that this approach is intended as a solution for a fixed office 'environment. Where a 'fixed' approach is not appropriate for your use 'please look at http://www.vbaexpress.com/kb/getarticle.php?kb_id=347 'for a more flexible approach to this... Private Sub Worksheet_Activate() 'Move to the right on "Enter" Application.MoveAfterReturnDirection = xlToRight 'select the next empty row Columns(1).Rows(65536).End(xlUp).Offset(1, 0).Activate End Sub ' ''<< TO USE THE ONLY ON ONE PART OF THE SHEET >> 'Private Sub Worksheet_SelectionChange(ByVal Target As Range) ' ' 'Replace D (below) with the column you want to use for an empty column ' If Left(Target.Address, 2) = "$D" Then Intersect(Target.EntireRow.Offset(1, 0), Range("A:A")).Select ' 'End Sub '<< TO USE THIS ON MORE THAN ONE PART OF THE SHEET >> 'The example below sets your data entry columns as being the columns A, B, and C 'To change this, replace A:A with whatever column you need to start from (e.gs. H:H or, AZ:AZ) 'Then replace D in $D$ with the single-letter column you want to use for an empty column 'For two-letter columns, replace D$ with the two letters. e.g. ($BD or $CV) and 'change (Target.Address, 2) to (Target.Address, 3). 'To set further data entry columns on a worksheet, just copy and paste 'the If Left(Targ...etc. line of code as many times as you wish 'and change the 'start' and empty 'end' columns as shown above. Private Sub Worksheet_SelectionChange(ByVal Target As Range) 'Replace D (below) with the column you want to use for an empty column If Left(Target.Address, 2) = "$D" Then Intersect(Target.EntireRow.Offset(1, 0), Range("A:A")).Select '<< Add any more that you want >> 'Replace H and E (below) with the columns you want to use If Left(Target.Address, 2) = "$H" Then Intersect(Target.EntireRow.Offset(1, 0), Range("E:E")).Select '(ditto) '(ditto) End Sub

How to use:

  1. Open an Excel workbook
  2. Select Tools/Macro/Visual Basic Editor
  3. In the VBE window, select Tools/Project Explorer
  4. Select the Sheet module you want this applied to
  5. Copy and paste the code into the sheet Module
  6. Now select File/Close and Return To Microsoft Excel
  7. Dont forget to save your changes...
 

Test the code:

  1. Make some entries in the worksheet and watch what has been selected on "Enter"
  2. The attached Zip file has an example of this and...
  3. Select Sheet2 and look at the example where this has been applied twice
  4. (You can apply this as many times as you like on any one sheet)
 

Sample File:

Carriage Return.zip 8KB 

Approved by mdmackillop


This entry has been viewed 142 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express