VBA & Macro Problems

How to Split or Overwrite the First 27 Characters of a Cell Using VBA

Olivia MillerOlivia Miller Nov 2, 2026 869 views

Question details

The user wants to use VBA to overwrite the active cell by retaining only the first 27 characters, while preserving the remaining text by moving it to an adjacent cell.

How to Overwrite or Extract the First 27 Characters of a Cell Using VBA
Product
Spreadsheet
Device & OS
not provided
Scenario
Automating text manipulation to split long strings within a cell based on an exact character count limit.
Observed behavior
The user requires a macro that accurately isolates the first 27 characters using string functions and shifts the subsequent characters to the next cell.
Before you start

Ensure your workbook is saved as a Macro-Enabled Workbook (.xlsm) and that you have enabled the Developer tab in your spreadsheet application to access the VBA editor.

Solution 1Recommended

Use Left and Mid VBA Functions to Split Cell Text

Utilize VBA's built-in string functions to extract the exact character count and offset the remaining text to a cell directly below.

The Left function extracts a specified number of characters from the start of a string, while the Mid function extracts characters starting from a designated position. By combining these, you can seamlessly split cell contents.

1
Open the VBA Editor

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

2
Insert a New Module

In the top menu, click on 'Insert' and select 'Module' to create a blank workspace for your macro.

3
Paste the Split Code

Copy and paste the following code into the module window: Sub CopyTwentySevenToNextCell() Dim first27 As String Dim after27 As String With ActiveCell first27 = Left(.Value, 27) after27 = Mid(.Value, 28) .Value = first27 .Offset(1, 0).Value = after27 End With End Sub

4
Run the Macro

Close the VBA editor. Select the cell containing your long text, press Alt + F8, select 'CopyTwentySevenToNextCell', and click 'Run'.

Use Left and Mid VBA Functions to Split Cell Text
Changing the Destination Cell: The .Offset(1, 0) property moves the remaining text to the cell directly below. If you want to move it to the cell to the right instead, change this to .Offset(0, 1).
Advanced Spreadsheet Editor

Execute Macros Seamlessly with WPS Spreadsheet

WPS Spreadsheet provides robust support for VBA macros in its advanced versions, allowing you to automate complex text manipulation tasks effortlessly while remaining fully compatible with standard spreadsheet formats.

  1. 1. Install WPS Office: Download and install the latest version of WPS Office.
  2. 2. Open Your Workbook: Open your Macro-Enabled Workbook (.xlsm) directly in WPS Spreadsheet.
  3. 3. Access the Developer Tools: Navigate to the Developer tab on the ribbon and click on the 'VBA Editor' icon.
  4. 4. Apply the Macro: Insert your text-splitting macro code and run it directly within the application to automate your workflow.
100% compatible with Microsoft Excel (.xlsx and .xlsm) formatsRobust environment for executing advanced VBA macrosLightweight application with a familiar, easy-to-use interface
QA img-9

Frequently Asked Questions

Can I split the text into the next column instead of the next row?

Yes. In the provided VBA code, modify the '.Offset(1, 0)' portion to '.Offset(0, 1)'. This adjustment tells the macro to move zero rows down and one column to the right.

What happens if the cell contains fewer than 27 characters?

The macro will not cause an error. The 'Left' function will simply extract all the available characters, and the 'Mid' function will return an empty string for the destination cell.

How do I apply this macro to multiple cells at once?

You can modify the macro to loop through a selected range. Instead of just referencing 'ActiveCell', wrap the logic in a 'For Each cell In Selection' loop, replacing '.Value' with 'cell.Value' and handling the offsets accordingly.