+ Reply to Thread
Results 1 to 14 of 14

VBA find multiple instances of value in range, return value in col for each row

  1. #1
    Registered User
    Join Date
    11-02-2019
    Location
    South Africa
    MS-Off Ver
    365
    Posts
    6

    VBA find multiple instances of value in range, return value in col for each row

    Hi guys

    I have a code I found some time back that will highlight all the cells in a range that contain a value.

    The range of data will have multiple instances of the value. What I would like to do is return the value of a certain col for each row that the value is found in the range.

    So basically, if the value is found in row 4, 6, 24, 55... I need the value of Col D, row 4 of sheet 1 to be put into sheet 2 col B, row 2 (first empty cell in col B). Then repeat this for all other rows where the value is found and put the values from Sheet 1 onto sheet 2 in the next empty cell in col B.

    Hope this makes sense.

    I cannot figure out or find a way of doing this.

    Help would be appreciated.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,897

    Re: VBA find multiple instances of value in range, return value in col for each row

    Welcome to the forum

    Please attach a sample workbook (not a picture or pasted copy). 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 then scroll down to Manage Attachments to open the upload window.
    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

  3. #3
    Registered User
    Join Date
    11-02-2019
    Location
    South Africa
    MS-Off Ver
    365
    Posts
    6

    Re: VBA find multiple instances of value in range, return value in col for each row

    Hi

    "Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window."
    Done this, file uploaded ...
    Attached Files Attached Files

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,897

    Re: VBA find multiple instances of value in range, return value in col for each row

    You did not present a mocked up copy of your expected results. I tried to correlate your explanation in Post 1 with your workbook in Post 3. Hopefully, I have done it correctly. Please advise any changes you require.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-02-2019
    Location
    South Africa
    MS-Off Ver
    365
    Posts
    6

    Re: VBA find multiple instances of value in range, return value in col for each row

    Hi Alan

    It is working for the most part... I have attached the actual file.

    What I am trying to get right is the following:
    In the Details sheet, I want to list everything that I am looking for in the DATA sheet in Row 1, this will be multiple entries in row 1.
    I then need to look for the value in Row 1 Col B in the DATA sheet and return the value in col F of the same row.

    So, essentially for each col containing a value in the details sheet, I need to find all the values in the DATA sheet and return the value in col F for each row the value is found.

    I could tweak it to work in the simple example, but when I try to use it with the actual data it does not work.

    Regards
    Attached Files Attached Files

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,897

    Re: VBA find multiple instances of value in range, return value in col for each row

    I have no idea what you are saying. It makes no sense to me. Suggest you use a real example explaining criteria, where it is found and what you want it to do. Generalities do not compute. I need to understand specifics. Where are we looking and what are we looking for. Once found, what needs to happen. Show a mocked up solution of several 4-6 records.

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    Hi !

    Quote Originally Posted by Stigmata View Post
    but when I try to use it with the actual data it does not work.
    As your first attachment does not reflect your actual data layout, it weird to practice like this
    or you are very confident with your Excel / VBA skills to amend the code to fit your real workbook !

    If the last attachment has at least some results filled with a better explanation like any forum expects
    in the initial post in order any helper does not have to guess as here this is not a mind readers forum …

  8. #8
    Registered User
    Join Date
    11-02-2019
    Location
    South Africa
    MS-Off Ver
    365
    Posts
    6

    Re: VBA find multiple instances of value in range, return value in col for each row

    Hi Alan and Marc

    At Marc, I am no expert but I can normally work things out... this has me totally stumped.

    At Alan, attached the sheet again with what I hope is an example of what to look for and what the expected outcome is.

    Below is the explanation, which is included in the attachment.

    This is what needs to be found in the DATA sheet.

    For each row in which this value is found, return the value on the same row in col F.

    There will always be multiple entries of the values in row 1.

    As an example, I have have highlighted the 1st 3 entries and what the expected result is for the first value in row 1...

    The first location is
    416,DU return 416,F
    419,DF return 419,F
    420,DV return 420,F

    and the last one is
    522,DF return 522,F

    I need to repeat this for columns in row 1 of the details sheet that contain a value.


    Hope I am making a bit more sense...
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831
    (removed as I have to check on a more recent Excel version than 2003 (columns limit to 256 …)
    Last edited by Marc L; 11-03-2019 at 02:16 PM.

  10. #10
    Registered User
    Join Date
    11-02-2019
    Location
    South Africa
    MS-Off Ver
    365
    Posts
    6

    Re: VBA find multiple instances of value in range, return value in col for each row

    Hey Marc

    Does my explanation make more sense now...?

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question

    In fact no according to your last attachment with the column B results : where they come from ?!

    Edit : I find now the issue for 'JB3T-14290-LTC.' as the DATA worksheet is 'JB3T-14290-LTC. ' (so with spaces at end) …
    Last edited by Marc L; 11-03-2019 at 06:52 PM.

  12. #12
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool

    A beginner starter demonstration to paste to the Sheet4(Details) worksheet module :

    PHP Code: 
    Sub Demo1()
        
    Dim C&, R&, Rg As RangeA$
            
    Me.UsedRange.Offset(11).Clear
            Application
    .ScreenUpdating False
    With Sheet1
    .UsedRange
        
    For 2 To Me.UsedRange.Columns.Count
                R 
    1
               Set Rg 
    = .Columns("CU:IV").Find(Cells(C).Value2 "*", , xlValuesxlWholexlByRows)
            If 
    Not Rg Is Nothing Then
                       A 
    Rg.Address
                
    Do
                       
    1
                       Cells
    (RC).Value2 = .Cells(Rg.Row6).Value2
                       Set Rg 
    = .Columns("CU:IV").FindNext(Rg)
                
    Loop Until Rg.Address A
            End 
    If
        
    Next
    End With
            Application
    .ScreenUpdating True
            Set Rg 
    Nothing
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 11-03-2019 at 07:29 PM. Reason: optimization …

  13. #13
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,613

    Re: VBA find multiple instances of value in range, return value in col for each row

    Please Login or Register  to view this content.
    Ben Van Johnson

  14. #14
    Registered User
    Join Date
    11-02-2019
    Location
    South Africa
    MS-Off Ver
    365
    Posts
    6

    Re: VBA find multiple instances of value in range, return value in col for each row

    Hey Experts

    Have not had a chance to go through everything just yet, crazy day.

    Marc, I still need to test your code...

    protonLeah, tried your quick and it seems to do everything that I need it to do.

    I will work on both tomorrow, there are still a few things I need to add in. So far it looks like with you guys helping I will be able to get to my end goal.

    Thanks a ton for the help thus far... off to a good start.

+ 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] Find Multiple Instances of Word in Range and Copy All
    By ScabbyDog in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-23-2016, 10:21 AM
  2. [SOLVED] Return multiple instances from a lsit
    By SKirkaldy in forum Excel General
    Replies: 5
    Last Post: 11-24-2015, 05:02 AM
  3. Find a value in a range which may have multiple instances of that value
    By wazimu13 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-23-2014, 06:08 PM
  4. [SOLVED] Complex VLOOKUP, multiple instances vertical, return subsequent instances horizontally
    By Miles_2804 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-12-2013, 11:54 AM
  5. Replies: 1
    Last Post: 02-12-2013, 06:02 PM
  6. Find all instances of a selected item and return all results
    By NewGuy OnBlock in forum Excel General
    Replies: 16
    Last Post: 01-11-2011, 10:24 PM
  7. Find Multiple instances of Single Criterion in Row & Return To a Single Col
    By Sam via OfficeKB.com in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 05-09-2006, 10:10 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