1

Find a Value Range in Excel

 2 years ago
source link: https://www.codesd.com/item/find-a-value-range-in-excel.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Find a Value Range in Excel

advertisements

I have two different sheets with 300,000 data in Excel. First sheet contains:

    S2_Symbol   Start_Pos   End Position
    STE        254857     267891
    PRI        748578     758962
    ILA        852741     963369
    VIS        789456     796325

Second:

   S1_Location
   789460
   852898
   748678

My output should be like this:

S1_Location   Symbol
789460         VIS
852898        ILA
748678        PRI

I have to find that S1_location falls in which S2_location and its corresponding Symbol. I have used INDEX formula in Excel but for each cell, I have to change the reference cell manually. I couldn't do it 300,000 data.

How can I do in an in Excel or should I use a script?


This solution assumes the following:

  • Start and End Positions for each S2 Symbol are unique (i.e. there is no intersection between the ranges allocated to each symbol)

  • Data in first sheet is located at A1:D17 (adjust ranges in formulas as needed)

  • Data in second sheet is locate at A1:B300010 (adjust ranges in formulas as needed)

The solution requires:

  • To add a working column in worksheet one. Enter this formula in D2 and copy till last record.

    =ROWS($A$1:$A2)
    
    

Fig. 1

  • Then in second worksheet enter this formula at B2 and copy till last record.

    =INDEX( Sheet1!$A$1:$A$17,
    SUMIFS( Sheet1!$D$1:$D$17,
    Sheet1!$B$1:$B$17, "<=" & $A2, Sheet1!$C$1:$C$17, ">=" & $A2 ) )
    
    

Fig. 2

It took aprox. less than 14 seconds to copy downwards and calculate the formulas in sheet 2. As it can be seen in figures 1 and 2 none of the tables need to be sorted.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK