+ Reply to Thread
Results 1 to 9 of 9

add specific item into last item for whole item based on where precede item

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-02-2019
    Location
    libya
    MS-Off Ver
    2010
    Posts
    758

    add specific item into last item for whole item based on where precede item

    Hi
    I want adding the item TML for each item doesn't precede items are (TR660,TMN,TTH) and add item TTN for each item precede item is TR660
    I put the result in second sheet but I want in the same first sheet. this is dummy data . the real data can contain about 1000 items for 1000 rows
    thanks
    Attached Files Attached Files
    Last edited by ABDELFATTA; 07-26-2022 at 07:16 AM.

  2. #2
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: add specific item into last item for whole item based on where precede item

    ARRAY formula in B2, copy down.
    =IF(ISNUMBER(FIND("TR660",'Trial Tracker'!B2)),'Trial Tracker'!$B2&" TTN",IF(SUM(COUNTIF('Trial Tracker'!B2,{"*TR660","*TMN","*TTH"}))=0,'Trial Tracker'!$B2&" TML",'Trial Tracker'!$B2))
    To enter ARRAY formula
    Copy and paste the formula in cell
    Press F2
    Press Ctrl+Shift+Enter together
    Excel covers the formula with {}.
    Attached Files Attached Files
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  3. #3
    Forum Contributor
    Join Date
    06-02-2019
    Location
    libya
    MS-Off Ver
    2010
    Posts
    758

    Re: add specific item into last item for whole item based on where precede item

    thanks. could achieve it by vba ,please?

  4. #4
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: add specific item into last item for whole item based on where precede item

    Hi ABDELFATTA,

    Try below code ...
    Sub test()
    
    Dim a: a = Sheets("Trial Tracker").[A1].CurrentRegion
    
    For x = 2 To UBound(a)
       Select Case True
          Case a(x, 2) Like ["*TR660"]: a(x, 2) = a(x, 2) & " TTN"
          Case a(x, 2) Like ["*TMN"], a(x, 2) Like ["*TTH"]: a(x, 2) = a(x, 2)
          Case Else: a(x, 2) = a(x, 2) & " TML"
       End Select
    Next
    
    Sheets("Trial Tracker").[F1].Resize(UBound(a), UBound(a, 2)) = a 'change location of data
    
    End Sub
    Last edited by nankw83; 07-27-2022 at 12:47 AM.
    If I was able to help, you can thank me by clicking the * Add Reputation under my user name

  5. #5
    Forum Contributor
    Join Date
    06-02-2019
    Location
    libya
    MS-Off Ver
    2010
    Posts
    758

    Re: add specific item into last item for whole item based on where precede item

    @nankw83 this is excellent !
    indeed I'm surprised from this short code can achieve my project.
    just question about this line
     Case a(x, 2) Like ["*TR660"]: a(x, 2) = a(x, 2) & " TTN"
    if I want add more than one items how I put multiple items in array I mean if I have TR660,TM1000,TN123 all of theses items should add to them item TTN

  6. #6
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: add specific item into last item for whole item based on where precede item

    You can just do it similar to the 2nd line shown below
    Case a(x, 2) Like ["*TMN"], a(x, 2) Like ["*TTH"]: a(x, 2) = a(x, 2)

  7. #7
    Forum Contributor
    Join Date
    06-02-2019
    Location
    libya
    MS-Off Ver
    2010
    Posts
    758

    Re: add specific item into last item for whole item based on where precede item

    just if it's possible to put multiple words in bracket like this
    HTML Code: 
    I know this is not right way ,but I see some codes put the words in array like this way . is it possible ?
    I'm asking just to learning not make the matter is hard

  8. #8
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: add specific item into last item for whole item based on where precede item

    I don't think it works this way. However, if you have a many strings that you want to put them in an array, maybe the code can be re-written differently to loop through each element in the array

    You can read more about the LIKE operator HERE

    Edit: In fact, the square brackets in my code are meaningless after refreshing my memory reading the link above
    Last edited by nankw83; 07-27-2022 at 11:13 AM.

  9. #9
    Forum Contributor
    Join Date
    06-02-2019
    Location
    libya
    MS-Off Ver
    2010
    Posts
    758

    Re: add specific item into last item for whole item based on where precede item

    @nankw83 I will satisfy your answering and use your way as you mentioned in post#6
    thanks for your time & answering

+ 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. [SOLVED] how to get the next item value based on the selected item in userform listbox ?
    By karmapala in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-27-2019, 05:49 AM
  2. [SOLVED] Search for item in multipage and show the item on the specific page + Collection
    By alexgoaga in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-02-2019, 05:37 PM
  3. Replies: 4
    Last Post: 12-31-2018, 02:42 PM
  4. [SOLVED] Formula to sum item costs based on item library
    By Fno in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-12-2017, 02:40 PM
  5. Replies: 2
    Last Post: 12-14-2016, 12:20 AM
  6. Automatically Input Cost of Item Based on Item Name?
    By boba7523 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-05-2014, 01:44 AM
  7. Taking the next item in a list into 1 of 2 tables based on the previous item time
    By SoleAris in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-07-2011, 04:59 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