+ Reply to Thread
Results 1 to 6 of 6

Find a value in a range which may have multiple instances of that value

  1. #1
    Registered User
    Join Date
    04-19-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    87

    Find a value in a range which may have multiple instances of that value

    Hi

    In summary, I have two columns of data as shown:

    Col A Col B

    1234 1234
    4567 1234
    8910 8910
    4567

    For each number in Col A, I need to search the cell address in Col B where it is, then add the
    values of the two cells to the right of that address to an array - (offset?).

    I will then place the results of that array onto a worksheet. Im not very good with arrays infact
    they really confuse me but i appreciate the speed they offer.

    My initial attempt is using "Range.find" as shown below, but cant figure how to add this to an array
    and then find the next occurrence of the number.


    Dim Var() As Variant, FindMe As Range, SearchThis As Range
    Dim Found As Range,Dim RngDP As Range, RngBatch As Range, J&, Batch As String, DP As String

    Please Login or Register  to view this content.


    Please let me know if any more info is needed.

    thanks

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Find a value in a range which may have multiple instances of that value

    Hi,

    You don't really need a VBA procedure to do this. In fact anything in VBA is inherently slower than doing the task in the Excel App. assuming of course that it's possible. And in this case it is. See attached.
    Assuming your data is in columns A & B and C & D contain the values that you want to sum then the simple array formula in row 1 copied down

    Formula: copy to clipboard
    Please Login or Register  to view this content.

    entered of course with Ctrl-Shift-Enter will work.
    Attached Files Attached Files
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Find a value in a range which may have multiple instances of that value

    So what would your expected results be in your example?

  4. #4
    Registered User
    Join Date
    04-19-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    87

    Re: Find a value in a range which may have multiple instances of that value

    thanks for your replies. I am not trying to add the numbers. They are ID numbers.
    I have just used dummy numbers to try and simplify my dataset.

    I have attached a spreadsheet with the steps i think are required, and desired outcome.

    A small correction on the offset requirement, the columns containing the data to be copied elsewhere are
    to the left of the cell containing the "found" value.

    thanks

    forum.xlsx

  5. #5
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Find a value in a range which may have multiple instances of that value

    Hi,

    One way, array formula** in G22 and copy across and down:

    =INDEX(A$2:A$10,SMALL(IF($C$2:$C$10=INDEX($G$2:$G$4,MATCH(TRUE,MMULT((--(ROW($G$2:$G$4)>=TRANSPOSE(ROW($G$2:$G$4)))),COUNTIF($C$2:$C$10,$G$2:$G$4))>=ROWS($1:1),0)),ROW(C$2:C$10)-MIN(ROW(C$2:C$10))+1),IFERROR(1+ROWS($1:1)-LOOKUP(ROWS($1:1),1+MMULT((--(ROW($G$2:$G$4)>=TRANSPOSE(ROW($G$2:$G$4)))),COUNTIF($C$2:$C$10,$G$2:$G$4))),ROWS($1:1))))

    Regards


    **Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Find a value in a range which may have multiple instances of that value

    Hi,

    Well on the face of it your results 'array' boils down to merely sorting A2:C10 using column C as the key.
    Then using a match on column C values to see if they exist in G2:G4 and delete the rows where there is no match.

    Or am I missing some subtlety here?
    Last edited by Richard Buttrey; 01-23-2014 at 06:11 PM.

+ 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. Replies: 8
    Last Post: 09-14-2013, 12:53 PM
  2. Find Multiple Instances of a String, copy whatever number value is in next Cell and add it
    By arvind3tthiru in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-26-2013, 11:26 PM
  3. Find number of instances data is with with a range
    By TimTDP in forum Excel General
    Replies: 9
    Last Post: 10-13-2011, 10:18 AM
  4. How to find Multiple Instances of a value
    By ksduded in forum Excel General
    Replies: 3
    Last Post: 04-28-2009, 10:51 AM
  5. Replies: 1
    Last Post: 04-08-2009, 05:24 AM

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