VBA & Macro Problems

Convert Only Inch Measurements to Centimeters in Excel Text

Partner EditorPartner Editor Oct 10, 2026 873 views

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.

How to Convert Only Inch Measurements to Centimeters Inside Excel Text Strings
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 you start

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.

Solution 1Recommended

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.

1
Open the VBA Editor

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

2
Insert a New Module

Click on 'Insert' in the top menu bar, and then select 'Module' to open a blank coding window.

3
Add the RegEx Conversion Code

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.

4
Use the Function in Excel

Close the VBA editor and return to your worksheet. You can now use your new custom function by typing `=ConvertInches(A1)` into a cell.

Use a Custom VBA Macro with Regular Expressions (RegEx)
Standardizing Data: If your data uses both 'in' and '"', you can adjust the RegEx pattern to look for multiple identifiers, ensuring no measurement is missed.
Efficient Data Processing with WPS Spreadsheet

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. 1. Open WPS Spreadsheet: Launch WPS Office and open the dataset containing your mixed text measurements.
  2. 2. Access the VBA Editor: Go to the 'Developer' tab and click on 'VB Editor', or simply press Alt + F11.
  3. 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.
Full compatibility with Microsoft Excel files and VBA macro scriptsAdvanced text manipulation capabilities for complex data cleaningFamiliar user interface ensuring zero learning curveFree and lightweight alternative to Microsoft Office
microsoft office alternative - wps office

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.