VBA & Macro Problems

How to Split Job Titles and Requisition Numbers Using VBA in Excel

Algirdas JasaitisAlgirdas Jasaitis Nov 11, 2026 868 views

Question details

The user needs to separate a combined string containing a job title and a requisition number (starting with 'P') into two distinct columns using a VBA macro.

How to Split Job Titles and Requisition Numbers Using VBA
Product
Excel
Device & OS
not provided
Scenario
Cleaning up HR or recruitment data where job titles and requisition numbers are merged in a single cell.
Observed behavior
The data is currently combined in one cell (e.g., 'Material HandlerP25-116021-2'), and the goal is to split the job title into the original cell and the requisition number into the adjacent cell.
Before you start

Ensure you have enabled the Developer tab in your spreadsheet application and saved your workbook as a Macro-Enabled Workbook (.xlsm) to prevent losing your VBA code.

Solution 1Recommended

Use a VBA Macro with Regular Expressions (RegExp)

This method uses VBScript.RegExp to accurately identify the 'P' prefix and split the text, placing the job title in the original cell and the requisition number in the next column.

Regular expressions are highly effective for pattern matching. In this case, the macro searches for the pattern where the requisition number starts with 'P' followed by digits and hyphens, ensuring accurate separation even if job titles vary in length.

1
Open the VBA Editor

Press ALT + F11 to open the Visual Basic for Applications (VBA) editor in your spreadsheet.

2
Insert a New Module

Click 'Insert' > 'Module' from the top menu to create a blank module for your code.

3
Paste the RegExp Macro Code

Copy and paste a VBA script utilizing 'CreateObject("VBScript.RegExp")'. Configure the RegExp pattern to match 'P\d+-\d+-\d+' (or your specific requisition format).

4
Run the Macro on Selected Cells

Select the range of cells containing the combined data in your worksheet, return to the Developer tab, click 'Macros', select your new macro, and click 'Run'.

Use a VBA Macro with Regular Expressions (RegExp)
Enable Regular Expressions: If you are using early binding in VBA, remember to enable 'Microsoft VBScript Regular Expressions 5.5' under Tools > References in the VBA editor.
Advanced Data Processing in WPS Spreadsheet

Use WPS Spreadsheet for VBA Macros and Data Splitting

WPS Office provides robust support for VBA macros, allowing you to run complex scripts like Regular Expressions to clean and split your data effortlessly.

  1. 1. Download and Install WPS Office: Get the free WPS Office suite from the official website and install it on your computer.
  2. 2. Open Your Data File: Launch WPS Spreadsheet and open your workbook containing the combined job titles.
  3. 3. Access the VBA Editor: Go to the 'Tools' tab and click on 'VBA Editor' (or press ALT + F11) to input your splitting macro.
  4. 4. Execute the Macro: Select your target cells and run the macro to instantly separate the requisition numbers into the adjacent column.
Fully compatible with Microsoft Excel VBA scripts and macrosSupports advanced data manipulation using VBScript.RegExpFree and lightweight alternative for heavy data processingSeamlessly open, edit, and save .xlsm and .xlsx files
microsoft office alternative - wps office

Frequently Asked Questions

Can I split this data without using VBA?

Yes, if the requisition number always has a fixed length or follows a specific delimiter, you can use Excel's 'Text to Columns' feature or functions like RIGHT(), LEFT(), and FIND(). However, for complex patterns like a 'P' followed by variable digits, VBA with RegExp is the most reliable method.

Why is my VBA macro not running?

Your macro security settings might be disabling VBA execution. Go to the Developer tab, click 'Macro Security', and select 'Enable all macros' (use with caution). Also, ensure your file is saved as a Macro-Enabled Workbook (.xlsm).

How do I modify the VBA code if my requisition number starts with a different letter?

You need to update the Regular Expression pattern in your VBA code. For example, if it starts with 'R', change the pattern string from 'P\d+...' to 'R\d+...' within the RegExp.Pattern property.

Will this macro overwrite existing data in the adjacent column?

Yes, the standard macro writes the extracted requisition number to the cell immediately to the right (Offset(0, 1)). Ensure the adjacent column is empty before running the macro to prevent data loss.