+ Reply to Thread
Results 1 to 22 of 22

Macro Script to return a cell values realted to a string

  1. #1
    Registered User
    Join Date
    05-08-2010
    Location
    AZ
    MS-Off Ver
    Excel 2007
    Posts
    49

    Macro Script to return a cell values realted to a string

    I am trying to create a script that will search for a specific string through a massive amount of garbled data and return a specific cell value if it finds a match. It would need to run a continuous loop until it gets to the end of the data. So in the end I get a nice clean list on another tab with all of the values I am looking for.

    For example...I want to return all of the "Results" that contain the string "Accept Referred".

    Result 1
    Accept Referred
    John
    Smith

    Result 2
    Accept
    Sam
    Smith
    303 E Washington
    Phx
    Az

    Result 3
    Accept Referred
    Frank
    Smith
    303 E Washington

    Result 4
    Accept
    Jim
    Smith
    Utah


    The final results would look like this:
    Result 1
    Result 3

  2. #2
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: Macro Script to return a cell values realted to a string

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    Regards!
    =DEC2HEX(3563)

    If you like someone's answer, click the star to give them a reputation point for that answer...

  3. #3
    Registered User
    Join Date
    05-08-2010
    Location
    AZ
    MS-Off Ver
    Excel 2007
    Posts
    49

    Re: Macro Script to return a cell values realted to a string

    Please see attached.
    Attached Files Attached Files

  4. #4
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: Macro Script to return a cell values realted to a string

    try this..

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-08-2010
    Location
    AZ
    MS-Off Ver
    Excel 2007
    Posts
    49

    Re: Macro Script to return a cell values realted to a string

    Worked on a small scale, but when I added the actual data I am using, it did not work properly. To give you a little background, I basically max out a Sheet with data and there may be 5,000 "Record IDs". There will be garbled data for each record ID that will have addresses, phone numbers, written notes, etc. Some will have the string, "added to accept list" and some will not. I need to have all of the Record IDs that have that string atatched to it. I have attached a better example of the data I have and what I want it to show. I have removed all data and added generic information.
    Attached Files Attached Files

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

    Re: Macro Script to return a cell values realted to a string

    Try
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    05-08-2010
    Location
    AZ
    MS-Off Ver
    Excel 2007
    Posts
    49

    Re: Macro Script to return a cell values realted to a string

    I get a "Type" Mismatch" error with "Sub test()" Jindon.

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

    Re: Macro Script to return a cell values realted to a string

    Since I can not download your latest file, I used your first file.

    See if it works.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    05-08-2010
    Location
    AZ
    MS-Off Ver
    Excel 2007
    Posts
    49

    Re: Macro Script to return a cell values realted to a string

    From what I can tell, you are using , char (2), to refer to the cell directly above the string, 'Accept Referred". The issue with that is, it's not always in that direct spot. It may be X amount of cells above the String. I should have made my example a little better to show that sorry...For Example:

    Result 1
    Accept Referred
    John
    Smith

    Result 2
    Sam
    Smith
    303 E Washington
    Phx
    Az
    Accept

    Result 3
    Frank
    Smith
    Accept Referred
    303 E Washington

    Result 4
    Utah
    Accept
    Jim
    Smith
    Result 1
    Accept Referred
    John
    Smith

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

    Re: Macro Script to return a cell values realted to a string

    Then this should do.
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    05-08-2010
    Location
    AZ
    MS-Off Ver
    Excel 2007
    Posts
    49

    Re: Macro Script to return a cell values realted to a string

    That did not work either...

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

    Re: Macro Script to return a cell values realted to a string

    Quote Originally Posted by owensjb2 View Post
    That did not work either...
    This doesn't help at all.

    How it is not working?

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

    Re: Macro Script to return a cell values realted to a string

    I could open your last file.
    This should do
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    05-08-2010
    Location
    AZ
    MS-Off Ver
    Excel 2007
    Posts
    49

    Re: Macro Script to return a cell values realted to a string

    Hmmm I think we are getting close...It worked with the test data but when I put in my actual data I get a "Run-Time error ' 13': Type Mismatch.

    The error is on the line:

    txt = Join(Application.Transpose(Sheets("raw data").Range("a1") _
    .CurrentRegion.Columns(1).Value), vbLf)

    Thoughts?

  15. #15
    Registered User
    Join Date
    05-08-2010
    Location
    AZ
    MS-Off Ver
    Excel 2007
    Posts
    49

    Re: Macro Script to return a cell values realted to a string

    Here is another version of a sample spreadsheet...This may be a better sample of what I have.
    Attached Files Attached Files

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

    Re: Macro Script to return a cell values realted to a string

    Don't wanna work with "better" sample.

  17. #17
    Registered User
    Join Date
    05-08-2010
    Location
    AZ
    MS-Off Ver
    Excel 2007
    Posts
    49

    Re: Macro Script to return a cell values realted to a string

    I have a lot of black spaces within all of the data, so I tried doing a find/replace for all of the spaces and replaced with no spaces. That helped with the error but now I am not returning any results because the String it's searching for is, .Pattern = "(Record added to )?Accept List" when now the result is, RecordaddedtoAcceptList. I tried .Pattern = "(Recordaddedto)?AcceptList" and got no results....

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

    Re: Macro Script to return a cell values realted to a string

    If you think you can alter the given codes, you should be able to write the whole codes for yourself already.

  19. #19
    Registered User
    Join Date
    05-08-2010
    Location
    AZ
    MS-Off Ver
    Excel 2007
    Posts
    49

    Re: Macro Script to return a cell values realted to a string

    Any other thoughts on where I'm having my issue?

  20. #20
    Registered User
    Join Date
    05-08-2010
    Location
    AZ
    MS-Off Ver
    Excel 2007
    Posts
    49

    Re: Macro Script to return a cell values realted to a string

    I think the main issue is that there is something within all of my data (a link, an integer, a function, something) that is causing that line to error. I just don't know what I can do to convert all of the data to acceptable data for the code you have provided.

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

    Re: Macro Script to return a cell values realted to a string

    As I said already, I don't wanna work with what you call "Better" sample anymore.

    If the last attached is exactly the same data structure and the key words, I can post the code, otherwise just wasting time for both.

    By the way do your country have an appreciation words for those who try to help you?

  22. #22
    Registered User
    Join Date
    05-08-2010
    Location
    AZ
    MS-Off Ver
    Excel 2007
    Posts
    49

    Re: Macro Script to return a cell values realted to a string

    YIKES!!!!

    In my country we help out until an issue is completely solved for those who have questions. At that point a well deserved Thank You would be in order. While I appreciate your help, your ability to just quit while I am still clearly having issues makes all of your hard work worthless to me.

    Instead of feeling gratitiude for all you attempted for me, I am now even more frustrated that I have code that almost works, but I can't figure out where my issue is.

    So, thank you for taking your time to "help" me with my issue and making it worse.

+ 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 return string of cell based on other cells
    By Justair07 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-23-2014, 12:32 PM
  2. [SOLVED] Return a string of values from a cell
    By MROMAR in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-28-2012, 03:04 PM
  3. Replies: 3
    Last Post: 10-03-2012, 03:09 AM
  4. Replies: 2
    Last Post: 09-24-2012, 03:11 PM
  5. [SOLVED] UDF to return string of values of all rows with cell matching reference cell
    By oemgacaesar in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-20-2012, 12:43 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