Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Replacing Cell Formats.

Replacing Cell Formats

Written by Allen Wyatt (last updated June 18, 2020)
This tip applies to Excel 97, 2000, 2002, and 2003


1

David needs to find and change every occurrence of a specific cell format in a multi-worksheet workbook. For example, he may need to find all cells that are formatted as Currency and change that format to General. He wonders how to accomplish the task.

The best way to go about this task depends on the version of Excel you are using. If you are using Excel 2003 you can simply use Excel's Find and Replace tool to make the change. Follow these steps:

  1. Press Ctrl+H. Excel displays the Replace tab of the Find and Replace dialog box.
  2. Click the Options button, if necessary, to enlarge the dialog box. (See Figure 1.)
  3. Figure 1. The Replace tab of the Find and Replace dialog box.

  4. Click the Format button to the right of Find What line. Excel displays the Find Format dialog box.
  5. Make sure the Number tab is displayed. (See Figure 2.)
  6. Figure 2. The Number tab of the Find Format dialog box.

  7. Use the controls in the dialog box to specify the format you want to find.
  8. Click OK to close the Find Font dialog box.
  9. Click the Format button to the right of Replace With line. Excel displays the Replace Format dialog box.
  10. Make sure the Number tab is displayed.
  11. Use the controls in the dialog box to specify the format you want to use as your replacement.
  12. Click OK to close the Replace Font dialog box.
  13. Use the Within drop-down list to choose Workbook.
  14. Click Replace All.

If you are using an older version of Excel, then the Find and Replace tool doesn't allow you to search or replace formatting. Instead, you must use a macro to do the changes. Here's an example of a macro that simply goes through all the used cells in the workbook and sets all the formats to General.

Sub FormatGeneral()
    Dim iSht As Integer
    Dim rng As Range

    For iSht = 1 To Sheets.Count
        Set rng = Worksheets(iSht).UsedRange
        With rng
            .NumberFormat = "General"
        End With
    Next
End Sub

If you wanted to get a bit more selective in which formats were replaced, then you'll need to check the existing format of the cells as you go through them. For instance, the following macro checks for any cells formatted as Currency and then changes only those cells to a General format.

Sub CurrencyToGeneral()
    Dim iSht As Integer
    Dim rng As Range
    Dim c As Range

    For iSht = 1 To Sheets.Count
        For Each c In Worksheets(iSht).UsedRange.Cells
            If c.NumberFormat = "$#,##0.00" Then
                c.NumberFormat = "General"
            End If
        Next c
    Next
End Sub

If you want to make the macro even more flexible, you can have it ask you to click on a cell that uses the format you want to find and then click on a cell that uses the format you want to change those cells to.

Public Sub UpdateFormats()
    Dim rFind As Range
    Dim rReplace As Range
    Dim rNextCell As Range
    Dim sNewFormat As String
    Dim sOldFormat As String
    Dim ws As Worksheet

    On Error Resume Next

    ' Determine the old format
    Do
        Set rFind = Application.InputBox( _
          prompt:="Select a cell that uses the format " & _
          "for which you want to search", _
          Type:=8)

        If rFind Is Nothing Then
            If MsgBox("Do you want to quit?", vbYesNo) = vbYes Then
                Exit Sub
            ElseIf InStr(1, rFind.Address, ":", vbTextCompare) > 0 Then
                MsgBox "Please select only one cell."
                Set rFind = Nothing
            End If
        End If
    Loop Until Not rFind Is Nothing
    sOldFormat = rFind.NumberFormat

    ' Determine the new format
    Do
        Set rReplace = Application.InputBox( _
          prompt:="Select a cell using the new format", _
          Type:=8)

        If rReplace Is Nothing Then
            If MsgBox("Do you want to quit?", vbYesNo) = vbYes Then
                Exit Sub
            ElseIf InStr(1, rReplace.Address, ":", vbTextCompare) > 0 Then
                MsgBox "Please select only one cell."
                Set rReplace = Nothing
            End If
        End If
    Loop Until Not rReplace Is Nothing
    sNewFormat = rReplace.NumberFormat

    ' Do the replacing
    For Each ws In ActiveWorkbook.Worksheets
        For Each rNextCell In ws.UsedRange
            If rNextCell.NumberFormat = sOldFormat Then
                rNextCell.NumberFormat = sNewFormat
            End If
        Next rNextCell
    Next ws
    MsgBox "The selected format has been changed."
End Sub

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9865) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Replacing Cell Formats.

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

Understanding Number Formatting Codes

When creating custom formats, you can employ a wide range of codes to define your formatting pattern. This tip focuses on ...

Discover More

Changing the Height of a Font

Scaling the width of a font is easy to do with Word's formatting capabilities. Scaling the height of the fonts is not so ...

Discover More

Setting Column Width in a Macro

Does your macro need to change the width of some columns in a worksheet? Here's how to do it.

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 (menu)

Adding Drop Shadows to Cells

Want to draw attention to what is in a cell? What better way than to add a drop shadow to that cell! Here's how you can ...

Discover More

Formatting Combo Box Text

If you insert objects, such as a combo box, in your worksheet, you may need a way to modify the font used in the object. ...

Discover More

Random Width and Height Changes

Have you ever been using a workbook, only to open it one day and find that Excel has changed the height of your rows or ...

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 two more than 7?

2015-10-19 23:10:46

Bharat

When I replace any word in excel, and apply difference format for the replaced word, in spite of replacing the format of that particular word it is replacing the entire row in the that format which I selected for the particular word.

Request you to help me on this


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon 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.