VBA & Macro Problems

How to Move to the Next Excel Row When Cells Are Locked

Ayan MasoodAyan Masood Oct 20, 2026 871 views

Question details

The user needs the cell selection to automatically jump from the last unlocked cell in a row to the first unlocked cell in the next row of a specific block (rack), rather than skipping to a completely different section.

How to Move to the Next Excel Row When the Next Cell Is Locked
Product
Excel
Device & OS
not provided
Scenario
Scanning barcodes into an inventory spreadsheet that contains multiple racks with both locked and unlocked cells.
Observed behavior
Excel's standard behavior skips over locked cells and moves the cursor to the next available unlocked cell globally, which causes it to jump to the next rack instead of the next row within the same rack.
Before you start

Before applying a macro or formula, verify that only your designated input cells are formatted as 'Unlocked' and that the worksheet is actively protected.

Solution 1Recommended

Use a VBA Macro to Control Cell Selection

Since standard Excel settings cannot restrict movement to a specific rack, a VBA macro can detect changes in specific cells and force the cursor to move to the exact starting cell of the next row.

This solution requires you to save your workbook as a Macro-Enabled Workbook (.xlsm). It triggers a specific cursor movement immediately after a barcode is scanned into the final cell of a row.

1
Open the VBA Editor

Press Alt + F11 on your keyboard to open the Visual Basic for Applications (VBA) editor.

2
Access the Worksheet Code

In the Project Explorer panel on the left, double-click the specific worksheet (e.g., Sheet1) where you are scanning barcodes.

3
Insert the Worksheet_Change Event

Paste a Worksheet_Change event script. You will need to write an IF statement that checks if the modified cell (Target) is the last unlocked cell in your row, and if so, use Range.Select to highlight the first unlocked cell of the next row.

4
Save as a Macro-Enabled Workbook

Go to File > Save As, and choose 'Excel Macro-Enabled Workbook (*.xlsm)' from the file type dropdown menu to ensure your code is preserved.

Use a VBA Macro to Control Cell Selection
Macro Security settings: Ensure that macro execution is enabled in your Excel Trust Center settings, otherwise the cursor movement code will not trigger when you scan a barcode.
Advanced Inventory Management

Automate Your Worksheets Easily with WPS Spreadsheet

WPS Spreadsheet offers robust VBA and macro support, allowing you to easily implement custom cursor movements for barcode scanning. Enjoy seamless compatibility with your existing Excel files.

  1. 1. Open Your Inventory File: Launch WPS Spreadsheet and open your existing inventory tracker.
  2. 2. Enable the Developer Tab: Navigate to the top ribbon, click on the 'Developer' tab, and select 'Visual Basic' to open the macro editor.
  3. 3. Add Your Custom Code: Double-click your active sheet in the left panel, paste your Worksheet_Change cursor movement code, and close the editor.
  4. 4. Protect the Worksheet: Go to the 'Review' tab, click 'Protect Sheet', and ensure only your specific input cells remain unlocked to guarantee accurate scanning.
Full VBA macro support for customized cursor navigationHighly compatible with Microsoft Excel (.xlsx and .xlsm) formatsIntuitive interface that simplifies protecting sheets and locking cellsLightweight software that runs efficiently on both new and older devices
microsoft office alternative - wps office

Frequently Asked Questions

Why does pressing Enter jump to another section instead of the next row?

When an Excel worksheet is protected, the Tab or Enter keys automatically move the cursor to the next available unlocked cell. If the immediate next cells in a row are locked, Excel will skip over them until it finds an unlocked cell, which is often in a completely different table or rack.

How do I unlock specific cells for barcode scanning?

Select the specific cells you want to scan into, right-click, and choose 'Format Cells'. Navigate to the 'Protection' tab, uncheck the 'Locked' box, and click OK. Finally, go to the 'Review' tab and click 'Protect Sheet' to enforce the rules.

Can I change the default Enter key direction in Excel?

Yes, you can change the global Enter key direction by going to File > Options > Advanced, and changing the 'After pressing Enter, move selection' setting. However, this global setting cannot conditionally skip specific blocks of locked cells within complex forms.

Do barcode scanners automatically press Enter?

Yes, the vast majority of USB and Bluetooth barcode scanners are configured by default to append a 'Carriage Return' (Enter key) suffix immediately after inputting the scanned text. This is what triggers Excel to move to the next cell.