Compiling Different Excel sheets WITHOUT a macro [closed]

痴心易碎 提交于 2019-12-12 06:44:02

问题


I have 4 different sheets with similar data, but in different formats. As an example:

Sheet A

Date        Buy-In     Game    Winnings
11/25/2013  $10        NFL     $18
11/28/2013  $10        NBA     $0

Sheet B

Sport       Buy-In     Date         Winnings
NFL         $5         11/26/2013   $9
NBA         $2         11/29/2013   $3.60

Sheet C

Buy-In      Game     Date         Winnings
$5          NFL      11/24/2013   $9
$2          NFL      11/21/2013   $3.60

Sheet D

Sport       Buy-In     Date         Winnings
NFL         $5         11/20/2013   $9
NBA         $2         11/22/2013   $3.60

I want to combine them into one sheet without using a macro. So the combined sheet would look like this:

Combined Sheet

Game      Date        Buy-In      Winnings
NFL       11/20/2013  $5          $9
NFL       11/21/2013  $2          $3.60
NBA       11/22/2013  $2          $3.60
NFL       11/24/2013  $5          $9
NFL       11/25/2013  $10         $18
NFL       11/26/2013  $5          $9
NBA       11/28/2013  $10         $0
NBA       11/29/2013  $2          $3.60

Is this feasible or even possible?


回答1:


You can do this using the INDIRECTfunction and a support table!

First you need to build a small support table that keeps the parameters for each input sheet:

  • In column B, use the following formula to determine the number of rows: =COUNTA(INDIRECT("'"&A5&"'!A:A"))-1.
  • For the range C5:F8, I used the formula =MATCH(C$4,INDIRECT("'"&$A5&"'!1:1"),0) - this will work for all columns that have the "proper" column name - only C6 and C8 needed to be entered manually, as you used "Sport" instead of "Game" here

Based on this support table, you can build your consolidation table. This has two sections - again 3 support columns to determine the sheet and the row number - and the data columns:

Use the following formulas:

  • Column H: =IF(ISTEXT(H4),1,IF(I5=1,H4+1,H4)) Logic: start with 1 and increase by 1 every time the row Id is reset to one - else keep the sheet ID from above
  • Column I: =IF(ISTEXT(I4),1,IF(I4=J4,1,I4+1)) Logic: start at 1 and increase by 1 until row ID in the row above is equal to the number of rows in the sheet from above. In the case, restart at 1
    • Column J: =INDEX($B$5:$B$8,H5) - get the number of rows for the current sheet from the config table
    • Column K:N: =OFFSET(INDIRECT("'"&INDEX($A$5:$A$8,$H5)&"'!A1"),$I5,INDEX(C$5:C$8,$H5)-1) - This is where the magic happens! ;-) Logic: Get the sheet name from the config table, use this in the INDIRECT function to retrieve the cell A1 from that sheet. Then offset by the row ID from the support column - and by the column ID for that sheet retrieved again from the config table.

See the example implemented in this file!



来源:https://stackoverflow.com/questions/20331700/compiling-different-excel-sheets-without-a-macro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!