How to Split Job Titles and Requisition Numbers Using VBA in Excel
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.

- 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.
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.
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.
Press ALT + F11 to open the Visual Basic for Applications (VBA) editor in your spreadsheet.
Click 'Insert' > 'Module' from the top menu to create a blank module for your 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).
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 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. Download and Install WPS Office: Get the free WPS Office suite from the official website and install it on your computer.
- 2. Open Your Data File: Launch WPS Spreadsheet and open your workbook containing the combined job titles.
- 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. Execute the Macro: Select your target cells and run the macro to instantly separate the requisition numbers into the adjacent column.

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.




