Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wrap Excel cursor to keep it within a specific range

Tags:

excel

vba

In Excel, I have three columns:

column1, column2, column3

I am entering data into excel using a barcode scanner that is attached to an IPAD. The barcode scanner sends ENTER after every scan. I believe that I can set excel up such that ENTER would cause the next column to be selected (instead of the next row)

However, I do not know how to have it go to the next row after there is an ENTER detected in column3. Right now I have this:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    If Target.Column = 3 Then
        If Target.Value = "{enter}" Then
            MsgBox "SDf"
        End If
    End If
End Sub

But Target.Value detects only the string inside the cell, it does not detect what has been pressed.

How do I get the next row to be selected after ENTER is detected in column 3?

like image 707
Alex Gordon Avatar asked Jul 06 '12 17:07

Alex Gordon


People also ask

How to move cursor to specific cell in Excel?

The Name box can help you easily move cursor to specific cell in Excel. 1. In the Name box, enter the specific cell reference you will jump to, and then press the Enter key. Then the cursor moves to the specified cell immediately.

How do I wrap text in a cell in Excel?

Method 1. Go to the Home tab > Alignment group, and click the Wrap Text button: Method 2. Press Ctrl + 1 to open the Format Cells dialog (or right-click the selected cells and then click Format Cells… ), switch to the Alignment tab, select the Wrap Text checkbox, and click OK.

Why is my data wrapping not working in Excel?

Data in the cell wraps to fit the column width, so if you change the column width, data wrapping adjusts automatically. If all wrapped text is not visible, it may be because the row is set to a specific height or that the text is in a range of cells that has been merged.

How do I open a spreadsheet without the cursor in it?

If the cursor was placed in the menu, quick tools area, or on another screen, then you could press Ctrl Home the cell highlighted would be A1 and everything was stable. If you manage to open a spreadsheet without the cursor in the cell area, there were no issues, until you introduced the cursor.


2 Answers

You don't need vba code for this.

The easiest way is to unlock the cells in those three columns and lock the rest of the cells. Once done, protect the entire sheet. However when protecting, ensure you uncheck the option called Select Locked Cells See screenshot. The yellow columns are unprotected.

enter image description here

The next step is to set excel so that after the data is entered and Enter key is pressed, the cursor moves to the next column. You can do that (Say in Excel 2010) from the File TAB | Options | Excel Options | Advanced

enter image description here

When the cursor reaches the last column and data is entered and the enter is pressed, the cursor will automatically move to the next row. See snapshot.

enter image description here

HTH

like image 167
Siddharth Rout Avatar answered Oct 12 '22 22:10

Siddharth Rout


In addition to Siddharth's excellent suggestion, here's an event-based approach:

Private Sub Worksheet_Change(ByVal Target As Range)

    'named (contiguous) range on input sheet
    Const DATA_NAME As String = "DATA"
    Dim rngData As Range, numCols As Long

    If Target.Cells.Count > 1 Then Exit Sub

    Set rngData = Me.Range(DATA_NAME)
    numCols = rngData.Columns.Count

    If Not Intersect(rngData, Target) Is Nothing Then
        If Target.Column < rngData.Columns(numCols).Column Then
            Target.Offset(0, 1).Select
        Else
            Target.Offset(1, -(numCols - 1)).Select
        End If
    End If

End Sub
like image 44
Tim Williams Avatar answered Oct 13 '22 00:10

Tim Williams