+ Reply to Thread
Results 1 to 6 of 6

Need Code to add number to text

Hybrid View

  1. #1
    Registered User
    Join Date
    12-06-2013
    Location
    sauk rapids, mn
    MS-Off Ver
    Excel 2003
    Posts
    7

    Question Need Code to add number to text

    Can someone show me a way to write a code to add a one number to a text.

    Example W001 change to W002.

    Thanks for the help

  2. #2
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Need Code to add number to text

    Hi,

    First, select the cell where the action want to performed, then run this sub.

    Sub Test()
      Dim str1 As String, i As Long
      str1 = Selection.Value
      For i = 1 To Len(str1)
          If IsNumeric(Mid(str1, i, 1)) Then
             str1 = Left(str1, i - 1) & Right(String$(255, "0") & Val(Mid(str1, i)) + 1, Len(str1) - i + 1)
             Selection.Value = str1
             Exit Sub
          End If
      Next i
    End Sub

    Regards
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  3. #3
    Registered User
    Join Date
    08-04-2009
    Location
    Golborne England
    MS-Off Ver
    2013
    Posts
    85

    Re: Need Code to add number to text

    Hi, Here is a formula that will add 1 to your code (column A) if the cell to the right in column B is not empty. This formula goes in column a row 2. You will need to type in a starting code in cell A1.

    =IF(B2<>"",LEFT(A1,1) & TEXT(RIGHT(A1,LEN(A1)-1)+1,"000"),"")

  4. #4
    Valued Forum Contributor Kamboj's Avatar
    Join Date
    09-25-2014
    Location
    India
    MS-Off Ver
    2003 - 2010
    Posts
    430

    Re: Need Code to add number to text

    Dear lylegross,
    If you'll use drag & fill function with mouse then it will add value.
    suppose you have w001,w002,w003 and if you drag the value then it will add further and you can use these values by copy paste

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Need Code to add number to text

    Assumes A1 has the text string.

    Sub lylegross()
    Dim x As Long
    x = Right([A1], 1)
    [A1] = Left([A1], Len([A1]) - 1) & x + 1
    End Sub

  6. #6
    Registered User
    Join Date
    12-06-2013
    Location
    sauk rapids, mn
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Need Code to add number to text

    Thanks for all your help
    I used the code but did a little modification and it works great.

    Thanks again

+ 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. Extract code which is number and text.
    By visha_1984 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-07-2015, 09:21 AM
  2. [SOLVED] VBA code for text to number
    By Mellie_d1 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-08-2012, 01:44 PM
  3. Code (incl text) as number
    By tcapewell in forum Excel General
    Replies: 1
    Last Post: 07-01-2011, 12:40 PM
  4. [SOLVED] Convert text strings to a code or number
    By MaxNY23 in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 03-23-2006, 06:50 PM
  5. number as text confusing code
    By Papa Jonah in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-07-2005, 04: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