+ Reply to Thread
Results 1 to 3 of 3

code to automatically change value of a cell from a number to a specific word

Hybrid View

  1. #1
    Registered User
    Join Date
    04-16-2014
    Location
    vancouver
    MS-Off Ver
    Excel 2007
    Posts
    18

    code to automatically change value of a cell from a number to a specific word

    Hi,

    I'm trying to find a way to change the value of all cells in a column based on the number in each cell. The data will be copied into the sheet from another and for the ease of use for the end user, I want the following numbers to automatically change to the corresponding values.

    01 = Acres
    02 = Width
    03 = Depth
    04 = Sq Ft
    05 = Units

    It would need to work automatically once the data is copied into the sheet and without the press of a button and without adding any new rows / columns to the sheet. Is this something that can be done with code or could it be triggered to happen when data is entered into a specific cell (A1)?

    I've uploaded an example and the column that would need to be changed is Column C. If anyone has any advice I would really appreciate it. Thanks in advance...
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: code to automatically change value of a cell from a number to a specific word

    It can be done automatically but I would be cautious about it's implementation. It would be better if you have a specific cell that you enter a final number into (like a date) you could use to trigger the macro to run at that time. I have attached the macro which will work when you paste data into the sheet, or do anything else in the sheet for that matter:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rCell As Range
    Dim strValue As String
    
    Application.ScreenUpdating = False
    
    For Each rCell In Range("C2:C" & Range("C" & Rows.Count).End(xlUp).Row)
        strValue = ""
        Select Case rCell.Value
            Case Is = "01"
                strValue = "Acres"
            Case Is = "02"
                strValue = "Width"
            Case Is = "03"
                strValue = "Depth"
            Case Is = "04"
                strValue = "Sq Ft"
            Case Is = "05"
                strValue = "Units"
        End Select
        
        If strValue <> "" Then
            Application.EnableEvents = False
            rCell.Value = strValue
            Application.EnableEvents = True
        End If
    Next rCell
    
    Application.ScreenUpdating = True
    
    End Sub

  3. #3
    Registered User
    Join Date
    04-16-2014
    Location
    vancouver
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: code to automatically change value of a cell from a number to a specific word

    Quote Originally Posted by stnkynts View Post
    It can be done automatically but I would be cautious about it's implementation. It would be better if you have a specific cell that you enter a final number into (like a date) you could use to trigger the macro to run at that time. I have attached the macro which will work when you paste data into the sheet, or do anything else in the sheet for that matter:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rCell As Range
    Dim strValue As String
    
    Application.ScreenUpdating = False
    
    For Each rCell In Range("C2:C" & Range("C" & Rows.Count).End(xlUp).Row)
        strValue = ""
        Select Case rCell.Value
            Case Is = "01"
                strValue = "Acres"
            Case Is = "02"
                strValue = "Width"
            Case Is = "03"
                strValue = "Depth"
            Case Is = "04"
                strValue = "Sq Ft"
            Case Is = "05"
                strValue = "Units"
        End Select
        
        If strValue <> "" Then
            Application.EnableEvents = False
            rCell.Value = strValue
            Application.EnableEvents = True
        End If
    Next rCell
    
    Application.ScreenUpdating = True
    
    End Sub

    This works perfectly. Thanks, stnkynts!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro to change colour of cell based on finding a specific word in the cell
    By Shelby761 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-24-2014, 09:46 AM
  2. automatically change the data entered into a cell to a specific format
    By aadifede in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-18-2012, 03:34 AM
  3. Modifying code to change number to word
    By vishwajeet_chakraort in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-07-2012, 04:32 AM
  4. Trying to change a code number into a word
    By moomog in forum Excel General
    Replies: 3
    Last Post: 09-16-2009, 08:13 PM
  5. If Cell Not Number Than Specific Word?
    By JK in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-17-2005, 03:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1