Convert Only Inch Measurements to Centimeters in Excel Text
Question details
The user needs a method to convert inch measurements (denoted by quotation marks or text) to centimeters within a mixed text string in Excel, leaving other numeric values like weights or identifiers unchanged.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Cleaning or standardizing mixed text datasets that contain multiple types of numeric data, such as product descriptions with both dimensions and weights.
- Observed behavior
- Standard formulas or basic find-and-replace methods alter every number in the text string, incorrectly converting values like pounds (lbs) or product IDs along with the inches.
Before applying a macro or query, standardize your measurement format (e.g., ensure all inches use the double quotation mark ") and make a backup copy of your data to test the conversion.
Use a Custom VBA Macro with Regular Expressions (RegEx)
Create a VBA User-Defined Function (UDF) using Regular Expressions to specifically target numbers followed by an inch mark and multiply them by 2.54.
Regular Expressions (RegEx) allow Excel to smartly parse text strings, identifying exact patterns. By instructing VBA to only look for numbers immediately followed by a double quotation mark ("), it safely converts the targeted values while completely ignoring other numbers like weights or identifiers.
Press Alt + F11 on your keyboard to launch the Microsoft Visual Basic for Applications (VBA) editor.
Click on 'Insert' in the top menu bar, and then select 'Module' to open a blank coding window.
Write or paste a VBA script that utilizes the VBScript.RegExp object to find the pattern `[0-9]+(\\.[0-9]+)?"`, extracts the number, multiplies it by 2.54, and replaces it in the string.
Close the VBA editor and return to your worksheet. You can now use your new custom function by typing `=ConvertInches(A1)` into a cell.

Transform Text Using Power Query
Use Power Query to split text strings, identify inch values conditionally, convert them, and merge the text back together.
Seamlessly Process Text and Macros with WPS Office
WPS Spreadsheet offers comprehensive support for advanced functions and VBA macros, allowing you to easily process complex mixed text strings and convert specific measurements without errors.
- 1. Open WPS Spreadsheet: Launch WPS Office and open the dataset containing your mixed text measurements.
- 2. Access the VBA Editor: Go to the 'Developer' tab and click on 'VB Editor', or simply press Alt + F11.
- 3. Insert Custom Function: Insert a new module, paste your inch-to-centimeter RegEx VBA code, and apply the custom function directly into your spreadsheet cells.

Frequently Asked Questions
Why doesn't the Excel CONVERT function work for this?
The CONVERT function only accepts strict numeric values as inputs. It cannot process mixed text strings containing words, multiple numbers, and different unit symbols simultaneously.
How do I ensure weights like pounds (lbs) are not converted?
By using a Regular Expression (RegEx) pattern in VBA that strictly targets numbers immediately followed by the double quotation mark ("). Numbers followed by 'lbs' or other text will not match the pattern and will be ignored.
Can I achieve this without VBA or Power Query using standard formulas?
While technically possible using highly complex nested combinations of MID, FIND, and SUBSTITUTE functions, it is incredibly prone to errors when a string contains multiple different numbers. VBA or Power Query is highly recommended for reliability.




