【问题标题】:Trying to combine spreadsheets in Excel尝试在 Excel 中合并电子表格
【发布时间】:2016-08-19 13:38:27
【问题描述】:

所以,我在 Excel 中有十几列数据,标题为 Company 和 Funded Balance。资金余额每年都在变化,我想制作一个时间表,每个公司每年的资金余额如何变化。

问题在于,每年都有一些公司没有资金余额,并且添加了一些新公司。有没有一种方法可以合并两个或多个电子表格,以便所有公司都按字母顺序列出那一年?我在下面附上了图片来说明我的意思:

第 1 列:

第 2 栏:

成品:

我在 VBA 方面相当缺乏经验,因此非常感谢您提供分步解决方案。谢谢!

【问题讨论】:

  • 这里不能指望完整的代码。展示您的尝试。我们将从那里提供帮助。
  • 我还没有编写任何代码。我希望有一个简单的解决方案,因为这似乎是一个相当简单的问题。
  • 正如我曾经读过的一些 SO 用户座右铭:“首先解决问题,然后编写代码”。我认为你应该开始列出所有公司。为此,我建议使用一个循环来遍历所有工作表。在该循环内,第二个循环扫描工作表中的所有行,并将公司名称复制到结果工作表(检查名称是否已存在)。
  • “所以,我有十几列数据......” “columns” 是指“worksheets”?

标签: vba excel


【解决方案1】:

首先,重要的是要知道这里没有人会为您编写代码。恐怕这不是这个网站的用途,而且无论如何都违反了指导方针。有很多很棒的在线资源可以教自己 VBA 的基础知识 - 例如http://www.excel-easy.com/vba.html

根据您对问题的描述,我不太明白您为什么需要编写 VBA 代码才能解决它。

我愿意:

1) 将所有数据复制并粘贴到一个电子表格中

2) 按公司名称字母顺序排序

3) 使用excel内置的“小计”功能

4) 将出现一个对话框。您要选择的选项是:每次更改公司名称时,使用函数 sum,将小计添加到 [funded balance 2005]、[funded balance 2006] 等。

这应该在一个电子表格中汇总每家公司每年的资金余额。

【讨论】:

    【解决方案2】:

    这是我为非 VBA 解决方案所做的:

    1. Place all of your tables on top of each other
    2. Remove the first two rows and any intervening blank rows 
       from all tables except the first one. It should look like one long table.
    3. In the first blank row of the second column put: 
       =IF(SUMIF($A$3:$A$8,$A3,B$3:B$8)=0,"",SUMIF($A$3:$A$8,$A3,B$3:B$8)) and adjust it 
       for your correct last row.
    4. Drag the formula down (for the neccesary number of rows) and over one column.
    5. With all the formulas selected, right click and hold any edge of the selection, 
       move off and back on again and paste as values only. (You must do this step for it to work properly)
    6. Copy and paste the company names.
    7. Select the three columns of your new rows and remove duplicates.
       Uncheck My Data has headers. 
    8. Sort the columns.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-02
      • 2018-06-16
      • 2022-01-22
      • 2013-07-03
      相关资源
      最近更新 更多