+ Reply to Thread
Results 1 to 9 of 9

Macro to INSERT a STRING in SEQUENCE or as the LAST entry

Hybrid View

  1. #1
    Registered User
    Join Date
    05-31-2013
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    83

    Macro to INSERT a STRING in SEQUENCE or as the LAST entry

    Its been a while,

    I have a column of order references so: MVC01, MVC02, MVC03, MVC03A, MVC04, MVC04A

    I want to be able to add a new entry in order, so MVC02A goes after MVC02. or if it is a new entry goes to the end. I want to insert a new row as opposed to move cells down.

    ive looked at match functions but that is using numbers, I saw a crazy long function for a string but thought there must be an easy way????

    this is what I have:

    Private Sub locaterow()
    
    
    Dim ianswer As String
    Dim i%, m
    
    ianswer = InputBox("oi")
    
    With Range("A:A")
        i = .Row
    
        m = Application.Match(ianswer, .Value, 1)
        
        m = Application.Match
    
        If Not IsError(m) Then i = .Cells(1, 1).Offset(m).Row
    End With
    
    MsgBox i
    
    
    End Sub


    any help much appreciated


    Thanks

    Jim

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Macro to INSERT a STRING in SEQUENCE or as the LAST entry

    What other possible combinations will there be? Is there likely to be MVC105? MVC1034? or only 2 digit numbers after MVC? Will it be MVC02A, 02B, 02C etc up to 02Z? 02AA?

    I have a feeling you be able to simply add the new entry to the bottom and then sort the data -that would work for the example provided so far I think.
    e.g.
    ianswer = inputbox("oi")
    Range("A" & rows.count).end(Xlup).row.offset(1,0) = ianswer
    Columns(1).sort Range("A1")

  3. #3
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Macro to INSERT a STRING in SEQUENCE or as the LAST entry

    Are they all the same format i.e. MVC01, 02 with the option for a suffix letter?
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  4. #4
    Registered User
    Join Date
    05-31-2013
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    83

    Re: Macro to INSERT a STRING in SEQUENCE or as the LAST entry

    They will always be MVC but could go above 100 doubt full into the 1000's.

    hadn't really thought about sorting them. not sure how id sort the entire rows as opposed to the column.

    For future reference tho how would I work this??


    Thanks

  5. #5
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Macro to INSERT a STRING in SEQUENCE or as the LAST entry

    activesheet.usedrange.sort Range("A1")
    maybe?

    It would give you 100 before 20 though. You would need to create a helper column with just the number and a helper column with just the letter. Then sort by the number column first and then the letter column.

  6. #6
    Registered User
    Join Date
    05-31-2013
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    83

    Re: Macro to INSERT a STRING in SEQUENCE or as the LAST entry

    Is there no way to do this using the MATCH method?

  7. #7
    Registered User
    Join Date
    05-31-2013
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    83

    Re: Macro to INSERT a STRING in SEQUENCE or as the LAST entry

    Ive also realised that it is the same issue when I come to organise my sheets, how can I put them in order??

    Thanks

  8. #8
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Macro to INSERT a STRING in SEQUENCE or as the LAST entry

    Probably but it would be very complicated, using sort would be easier.

  9. #9
    Registered User
    Join Date
    05-31-2013
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    83

    Re: Macro to INSERT a STRING in SEQUENCE or as the LAST entry

    Thanks for the help decided your right its easier to relabel everything to 001 and hope it doesn't go over a 1000 lol

    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. Macro to insert new VLOOKUP table entry
    By eb710 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-06-2013, 10:46 AM
  2. Replies: 2
    Last Post: 01-02-2013, 08:35 AM
  3. Need help for create a macro to auto insert date time after entry
    By DentedGold in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-07-2012, 11:45 AM
  4. [solved]Auto Sequence Date of of previous entry
    By kamelkid2 in forum Excel General
    Replies: 3
    Last Post: 12-15-2011, 10:29 AM
  5. Macro to insert many pictures in sequence?
    By applegatecz in forum Word Programming / VBA / Macros
    Replies: 0
    Last Post: 01-13-2010, 04:35 PM

Tags for this Thread

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