Converting Text Notation Values to Numeric Values

Written by Allen Wyatt (last updated November 23, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


1

Aakhil receives his bank statement as a PDF file each month. When he converts it to an Excel file, the numbers end up in the format 5,000CR and 257DB. Aakhil needs to convert these obviously text values into actual numbers, with the CR amounts being negative and the DB amounts being positive.

A formula can be used to do the conversion from a text to a numeric value, and there are several different formulaic approaches that could be used. Here's a very simple one, assuming your text value is in cell A1:

=LEFT(A1,LEN(A1)-2)*IF(RIGHT(A1,2)="CR",-1,1)

This formula assumes that the text value ends in either CR or DB, as Aakhil seems to indicate. The formula uses the LEFT function to return everything in the cell except the last two characters, and then multiplies that by either -1 (if the last two characters are CR) or 1. The multiplication ensures that what is returned by the formula is a numeric value instead of a text value.

Again, the formula assumes that the ONLY last two characters are CR or DB. If they might be something else, or if there might not be any trailing characters at all, then the following formula would be a better approach:

=LEFT(A1,LEN(A1)-2)*IF(RIGHT(A1,2)="DB",1,IF(RIGHT(A1,2)="CR",-1,0))

This version checks for CR and DB and multiplies accordingly. If the last two characters are anything else, then it is multiplied by 0. You can then check all the 0 results and manually adjust them according to your needs.

If you are using Excel 2021 or the version of Excel with Office 365, then you could build a robust formula in the following manner:

=LET(s,RIGHT(A1,2),n,LEFT(A1,LEN(A1)-2),IF(s="DB",--n,IF(s="CR",-n,"PROBLEM")))

The formula uses the LET function to assign the right two characters of A1 to the s variable and the rest of the characters to the n variable. If s is equal to "DB," then a positive (--) version of n is returned; if s is equal to "CR," then a negative version of n is returned; if s is equal to anything else, then the text "PROBLEM" is returned. This makes it very easy to identify any problem areas you need to check.

If you need to do the conversion quite often, then you might find it helpful to use a macro. The following will evaluate any selected cells and properly convert them as long as they end in either DB or CR:

Sub FixCRDB()
    Dim c As Range
    Dim sRaw As String
    Dim sNum As String

    For Each c In Selection
        sRaw = Trim(c.Value)
        If Len(sRaw) > 2 Then
            sNum = Left(sRaw, (Len(sRaw) - 2))
            If IsNumeric(sNum) Then
                Select Case Right(sRaw, 2)
                    Case "CR"
                        c.Value = -CDbl(sNum)
                    Case "DB"
                        c.Value = CDbl(sNum)
                End Select
            End If
        End If
    Next c
End Sub

Again, select the cells you want to convert and run the macro. Those ending in CR or DB are converted to numeric values—either positive or negative, as Aakhil desired—and anything else is ignored.

Another way to handle reading the PDF and doing the conversion on a regular basis is to use Power Query. How to actually set that up is beyond the scope of this tip, though, as the format of the PDF itself is critical to doing the transformation. Understand, however, that you could set up the query once and reuse it, month after month, to import your bank statement into Excel.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13940) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Keeping Part of a Paragraph with the Next Block of Text

If you are a WordPerfect user, you may be very familiar with the block-protect feature and wonder if there is a similar ...

Discover More

Making Macros Available without Using the Normal Template

If you save your macros in your Normal template, they'll be available whenever you are using Word. What if you don't want ...

Discover More

Appending to a Non-Document Text File

Your macros can easily add information to the end of an existing text file. This is done by opening the target file in ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

More ExcelTips (ribbon)

Determining "Highest Since" or "Lowest Since"

When compiling statistics on a collection of data points, you may want to know whether a particular value is the "highest ...

Discover More

Finding Circular References

If you have circular references in a workbook, you may see an error message appear when you first open that workbook. If ...

Discover More

Automatically Numbering Rows

Adding row numbers to a column of your worksheet is easy; you just need to use a formula to do it. Here's a quick look at ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is five more than 8?

2024-11-25 09:02:33

Mike H

With the advent of Power Query and being able to "get data" direct from a PDF would use PQ to extract and then use the tools in PQ to resolve instead of this.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.