+ Reply to Thread
Results 1 to 5 of 5

VBA code for adding text prefix to an integer

Hybrid View

g-unit84 VBA code for adding text... 03-11-2013, 07:56 AM
patel45 Re: VBA code for adding text... 03-11-2013, 09:35 AM
g-unit84 Re: VBA code for adding text... 03-11-2013, 09:53 AM
Jakobshavn Re: VBA code for adding text... 03-11-2013, 09:41 AM
g-unit84 Re: VBA code for adding text... 03-11-2013, 09:54 AM
  1. #1
    Registered User
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2007
    Posts
    3

    VBA code for adding text prefix to an integer

    Hi Everyone

    I would like to add a text prefix to a number I have created as an integer, as follows:

    Dim POnumber As Integer
    '
    POnumber = Sheets("Register2").Cells(Rows.Count, "A").End(xlUp) + 1

    The "POnumber" is to increase by 1 on the search in a table, I then want to add the letters "PO" to the beginning of this new number.

    Thank you.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: VBA code for adding text prefix to an integer

    If you want POnumber = the last used row you have to change so
    POnumber = Sheets("Register2").Cells(Rows.Count, "A").End(xlUp).row + 1
    If you want add the letters "PO" to the beginning of POnumber
    newstring="PO" & POnumber
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: VBA code for adding text prefix to an integer

    Hi Patel45

    Thanks for the help, it worked perfectly.

  4. #4
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: VBA code for adding text prefix to an integer

    Try:

    Sub sjkdfhsdf()
    Dim POnumber As Integer, NextRow As Long, St As String
    '
    St = Sheets("Register2").Cells(Rows.Count, "A").End(xlUp)
    NextRow = Sheets("Register2").Cells(Rows.Count, "A").End(xlUp).Row + 1
    POnumber = Replace(St, "PO", "") + 1
    Sheets("Register2").Cells(NextRow, "A").Value = "PO" & POnumber
    
    End Sub
    Gary's Student

  5. #5
    Registered User
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: VBA code for adding text prefix to an integer

    Hi Jakobshavn

    Thanks for the reply.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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