Excel: Listing Numbers In Between 2 Numbers

后端 未结 2 1268
一向
一向 2021-01-27 09:01

I was wondering if anyone knew of a formula to list all the numbers between 2 values, so for example if cell F2 had 12 in it and G2 had 17 in it I\'d like a formula that would s

2条回答
  •  自闭症患者
    2021-01-27 09:51

    Just because @teylyn said it couldn't be done with a formula - here is a formula based solution:

    First you need to create the full list of numbers that you are likely to need as a string, this could be in another cell or my preference would be to create a named range.

    So create a new named range called rng and in the Refers to text box add the following formula:

    =",1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,"
    

    For this solution to work you have to know the full range upfront, also note the leading and trailing comma.

    Then enter the following formula into cell H2:

    =SUBSTITUTE(LEFT(rng,FIND(","&G2&",",rng)+LEN(G2)),LEFT(rng,FIND(","&F2&",",rng) ),"")
    

    To same the tedium of creating the number range string I used the following Powershell code to create and copy it to the clipboard:

    1..20 -join ',' | % {"=`",$($_),`""} | clip.exe 
    

    Just change the 20 in the above code for whatever range you require.

提交回复
热议问题