All we want is, the data to be copied from columns 2 & 3 of Query Table to Columns 5 & 6 of Expected Output table depending upon the values present in Column 1 of Query table. As in first case we have four consecutive numbers 1,2,3,4 highlighted as yellow in Column 1. Thus in this case we have total 4 numbers and the values picked from column 2 and column 3 and copied to column 5 & column 6 are 3 because(4-1 = 3). For the last value i.e. 4 in this case in colun 1 a blank line will be inserted corresponding to it in expected output table. Simililarly in next case we have we have five consecutive numbers 1,2,3,4,5 highlighted as red in Column 1. Thus here we will pick and copy only 4 values because 5-1 = 4, For the last value i.e. 5 in this case in colun 1 a blank line will be inserted corresponding to it in expected output table. A case where only one value is present in column 1 as marked as light value no value should be picked because here 1-1 = 0. Actually this is to be done for thousands of rows which is not posisble manually. If you have any issue in understanding the whole problem please communicate me on meetvivek72attherategmail.com