+ Reply to Thread
Results 1 to 18 of 18

Mapping strings in cell to value, and then keeping certain rows based on certain criterias

  1. #1
    Registered User
    Join Date
    05-01-2023
    Location
    Singapore
    MS-Off Ver
    (Version 2302 Build 16.0.16130.20378) 64-bit
    Posts
    66

    Mapping strings in cell to value, and then keeping certain rows based on certain criterias

    Testy.xlsm

    photo_2023-05-31 21.07.38.jpeg

    I have this excel file. The tenors in row C goes from O/N (overnight), 1 month, 3 months, 6 months and 1 year. I wish to give a value to the tenors such that it goes in ascending order based on its duration, but remain the abbreviations in the Column C.

    After doing that, I want to delete rows by keeping only the highest Tenor, while remaining the relevant Entity, Bank Name and Pillar (AB_CD or Placement).

    With reference to the screenshot I've attached above, after running the vba code, my first 3 rows should look like this:
    A2: China, B2: Bank of America, C2: 1Y, D2: AB_CD, E2: SGD, F2: 118000000, G2: 0, H2: 118000000
    A3: China, B3: Bank of America, C3: 1Y, D3: Placement, E3: SGD, F3: 118000000, G3: 0, H3: 118000000
    A4: London, B4: Bank of China, C4: 1Y, D4: AB_CD, E4: SGD, F4: 118000000, G4: 0, H4: 118000000

    I don't really know how to start the code, I would really appreciate some help on this!
    Last edited by webcam723; 05-31-2023 at 09:30 AM.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Mapping strings in cell to value, and then keeping certain rows based on certain crite

    Need vba?

    I2:

    =MATCH(C2,{"1Y","6M","3M","1M","O/N"},0)

    Copy down and sort by this column in ascending order.

  3. #3
    Registered User
    Join Date
    05-01-2023
    Location
    Singapore
    MS-Off Ver
    (Version 2302 Build 16.0.16130.20378) 64-bit
    Posts
    66

    Re: Mapping strings in cell to value, and then keeping certain rows based on certain crite

    I would prefer if I could run everything via VBA, would you have any insights as to do that?

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Mapping strings in cell to value, and then keeping certain rows based on certain crite

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-01-2023
    Location
    Singapore
    MS-Off Ver
    (Version 2302 Build 16.0.16130.20378) 64-bit
    Posts
    66

    Re: Mapping strings in cell to value, and then keeping certain rows based on certain crite

    Running this code crashes my excel, how can i get by that?

    Update: I deleted the second last line of the code and it doesnt crash anymore.
    Last edited by webcam723; 05-31-2023 at 10:23 AM.

  6. #6
    Registered User
    Join Date
    05-01-2023
    Location
    Singapore
    MS-Off Ver
    (Version 2302 Build 16.0.16130.20378) 64-bit
    Posts
    66

    Re: Mapping strings in cell to value, and then keeping certain rows based on certain crite

    Also, I don't wish to change the order of the rows. Can you edit the code to fulfill this criteria?

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Mapping strings in cell to value, and then keeping certain rows based on certain crite

    It is working here without problem.

    Waht do you mean by
    Quote Originally Posted by webcam723 View Post
    Also, I don't wish to change the order of the rows. Can you edit the code to fulfill this criteria?
    ?

    Upload a workbook with before/after.

  8. #8
    Registered User
    Join Date
    05-01-2023
    Location
    Singapore
    MS-Off Ver
    (Version 2302 Build 16.0.16130.20378) 64-bit
    Posts
    66

    Re: Mapping strings in cell to value, and then keeping certain rows based on certain crite

    I will try to fix it on my side. Thanks for your help on this!

    By any chance, do you understand how to go about doing the second part of my problem?

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Mapping strings in cell to value, and then keeping certain rows based on certain crite

    I don't even understand what you are asking.

  10. #10
    Registered User
    Join Date
    05-01-2023
    Location
    Singapore
    MS-Off Ver
    (Version 2302 Build 16.0.16130.20378) 64-bit
    Posts
    66

    Re: Mapping strings in cell to value, and then keeping certain rows based on certain crite

    Let me simplify my question.

    Attachment 831311

    With reference to the screenshot, Column A has repeating unique names (A,B,C), and each has different tenors (to which I assign a number in Column C, 1 to 5, 1 being the shortest duration O/N and 5 being the longest duration 1Y). Each row also has a unique number in Column D.

    The goal is to keep one row of each unique name that has the highest tenor. (The supposed output is shown in the screenshot too).

    This should be easier to understand.

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Mapping strings in cell to value, and then keeping certain rows based on certain crite

    Picture you posted is invalid, so no use.

    Upload a workbook, not a picture.

  12. #12
    Registered User
    Join Date
    05-01-2023
    Location
    Singapore
    MS-Off Ver
    (Version 2302 Build 16.0.16130.20378) 64-bit
    Posts
    66

    Re: Mapping strings in cell to value, and then keeping certain rows based on certain crite

    Testy.xlsm


    I attached the workbook, let me know if you cannot download it. Refer to sheet 2 for the example im referring to below.

    Column A has repeating unique names (A,B,C), and each has different tenors (to which I assign a number in Column C, 1 to 5, 1 being the shortest duration O/N and 5 being the longest duration 1Y). Each row also has a unique number in Column D.

    The goal is to keep one row of each unique name that has the highest tenor, the supposed result is given in the workbook as well.

    My goal is to run it just via VBA code.

    Sorry im new to this platform!

  13. #13
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,617

    Re: Mapping strings in cell to value, and then keeping certain rows based on certain crite

    Please Login or Register  to view this content.
    Based on your "sorted" input data

    Sheet2 is your input: copy to Sheet1 and "RUN"
    Attached Files Attached Files
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Mapping strings in cell to value, and then keeping certain rows based on certain crite

    Still not clear
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by jindon; 05-31-2023 at 11:32 AM. Reason: typo

  15. #15
    Registered User
    Join Date
    05-01-2023
    Location
    Singapore
    MS-Off Ver
    (Version 2302 Build 16.0.16130.20378) 64-bit
    Posts
    66

    Re: Mapping strings in cell to value, and then keeping certain rows based on certain crite

    That was amazing! I really appreciate the help!

    Can I get some help with a few adjustments to the end result?

    1. The same Bank Names will be top and bottom of each other, with AB_CD on top and Placement below. (Refer to Sheet "After Running Code" Range K2:R6, Bank of America followed by UBS.)
    2. Then add the total up for Limit, Exposure and Remainder for each bank in each entity. (in Millions, so the value needs to be /1000000)
    3. As for the Pillar Column, if the Bank has both the AB_CD and Placement Pillars, the cell below it will reflect "AB_CD & Placement".
    Similarly if it only has AB_CD or only has Placement, then it will show that only.

    Test 2.xlsm

    Please use the Test 2 workbook to work on the above!
    Last edited by webcam723; 05-31-2023 at 12:00 PM.

  16. #16
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2503 Win 11
    Posts
    24,647

    Re: Mapping strings in cell to value, and then keeping certain rows based on certain crite

    crossposted: https://www.mrexcel.com/board/thread...erias.1238254/

    Rule 03: Cross-posting Without Telling Us

    Your post does not comply with Rule 3 of our Forum RULES. Do not cross-post your question on multiple forums without telling us about your threads on other forums.

    Post a link to any other forums where you have asked the same question.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Read this to understand why we ask you to do this.

    I have added the crosspost reference for you today. Please comply with this and all our rules in the future

    However, if you continue to crosspost, you can expect to have your thread BLOCKED until you update it yourself.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  17. #17
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,617

    Re: Mapping strings in cell to value, and then keeping certain rows based on certain crite

    Please Login or Register  to view this content.
    Final output in 2After running code" columns T to AA
    Attached Files Attached Files

  18. #18
    Registered User
    Join Date
    05-01-2023
    Location
    Singapore
    MS-Off Ver
    (Version 2302 Build 16.0.16130.20378) 64-bit
    Posts
    66
    Can you breakdown and explain the top part of the code?

+ 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] Replacing multiple strings in one cell according to a mapping table (lookup)
    By zits1 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-25-2022, 08:27 AM
  2. How to hide some rows based on a specific cell value whilst keeping all unused rows hidden
    By Consultant101 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-15-2021, 06:41 PM
  3. [SOLVED] mapping words to strings
    By calitopgun in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 01-13-2021, 02:55 PM
  4. Replies: 0
    Last Post: 05-30-2020, 03:14 AM
  5. Replies: 4
    Last Post: 05-09-2017, 06:05 AM
  6. Copy Rows from one sheet to another based on mapping
    By donk04 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-10-2016, 03:53 AM
  7. delete rows based on three criterias
    By cbk40060 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-15-2015, 02:26 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