VBA & Macro Problems

WPS Spreadsheet VBA: Move New Dates Right and Clear the Input Cell

Huda QurayshiHuda Qurayshi Nov 12, 2026 868 views

Question details

The user needs to automatically move a date entered in column B to the next available column on the same row, then clear column B for the next entry.

Product
WPS Spreadsheet VBA macros
Device & OS
not provided
Scenario
A worksheet receives new dates in column B and should build a horizontal record across the same row without requiring manual copying.
Observed behavior
The desired worksheet change event moves the entered value to the next available column on its row and clears the original input cell.
Before you start

Open the target workbook and identify the worksheet where dates will be entered in column B. Confirm that macro execution is enabled and prepare to save the file in the macro-enabled .xlsm format.

Solution 1Recommended

Add a worksheet change event to move dates from column B

Use this solution when each new value entered in column B should move to the next available column on the same row automatically.

The event must be placed in the specific worksheet module so it responds to edits on that sheet. Events are temporarily disabled while the value is moved and cleared, preventing the macro from triggering itself repeatedly.

1
Open the VBA editor

In WPS Spreadsheet, open the workbook, press Alt+F11, and locate the target worksheet under the workbook in the Project Explorer.

2
Open the worksheet module

Double-click the relevant worksheet, such as Sheet1, in the Project Explorer. Do not paste the event into Insert > Module or another standard module.

3
Insert the change-event code

Paste this code into the worksheet code window: Private Sub Worksheet_Change(ByVal Target As Range) If Target.CountLarge > 1 Then Exit Sub If Target.Column = 2 And Target.Value <> "" Then Application.EnableEvents = False Cells(Target.Row, Cells(Target.Row, Columns.Count).End(xlToLeft).Column + 1).Value = Target.Value Target.ClearContents Application.EnableEvents = True End If End Sub

4
Save and test the macro-enabled workbook

Close the VBA editor, choose File > Save As, select the Excel Macro-Enabled Workbook (*.xlsm) format, and enable macros when prompted. Enter a date in column B and verify that it moves right on the same row while the input cell is cleared.

Expected result: When a single nonblank value is entered in column B, it is written to the next available column on that row and the original column B cell becomes empty.

Automate Date Tracking with WPS Spreadsheet VBA

WPS Spreadsheet lets you place a worksheet change event in the correct sheet module, automate the horizontal date-entry workflow, and save the workbook as a macro-enabled file for repeated use.

  1. 1. Open the workbook in WPS Spreadsheet: Launch WPS Office, select Spreadsheet, and open the workbook that contains the date-entry sheet.
  2. 2. Access the worksheet VBA module: Press Alt+F11, select the target worksheet in the Project Explorer, and open its code window.
  3. 3. Paste the Worksheet_Change event: Insert the event code that detects column B, writes the value to the next available column, and clears the original cell.
  4. 4. Save as an XLSM file: Use File > Save As and choose Excel Macro-Enabled Workbook (*.xlsm), then enable macros and test a date entry in column B.
Automatically moves new dates from column B to the next available cell on the same row.Clears the input cell so it is ready for the next date.Supports familiar VBA worksheet-event workflows in macro-enabled workbooks.Maintains compatibility with Microsoft Excel .xlsm and .xlsx file formats.
microsoft office alternative - wps office

Frequently Asked Questions

Where should the Worksheet_Change code be pasted in WPS Spreadsheet?

Press Alt+F11, find the target sheet under the workbook in Project Explorer, and double-click that worksheet. Paste the code in its worksheet module, not under Insert > Module.

Why does the macro only respond to values entered in column B?

The condition Target.Column = 2 restricts the event to column B. Change the number if the input column is different; for example, column C is column 3.

What happens if the row already contains values to the right?

The macro checks the last used cell in that row with End(xlToLeft) and writes the new value in the next column, preserving the existing entries.

Why must events be disabled while the macro runs?

Writing a value and clearing the input cell are worksheet changes. Application.EnableEvents = False prevents those actions from calling Worksheet_Change again and creating a recursive loop.

Which file format is required to keep this VBA macro?

Save the workbook as Excel Macro-Enabled Workbook (*.xlsm). If you save it as a regular .xlsx file, the VBA project may not be retained, and macros must be enabled when the workbook opens.