简体   繁体   English

Excel VBA将列堆叠在不同的工作表中

[英]Excel VBA to stack columns in different sheets

I have an Excel workbook with 2 sheets inside. 我有一本Excel工作簿,里面有2张纸。 Both sheets have tables that can change in length (row count). 两张纸都有可以更改长度(行数)的表。 I want to be able to have VBA take table1 in sheet1 and align it within table2 on sheet2. 我希望能够使VBA在sheet1中使用table1并将其在sheet2的table2中对齐。

Here's where it gets tricky. 这就是棘手的地方。 The columns do not line up. 列不对齐。 For example, "Company" in sheet1 might be in column E. However, in sheet2 it's in column V. There are also blanks in the columns. 例如,sheet1中的“公司”可能在E列中。但是,在sheet2中,它在V列中。这些列中也有空白。 Which is ok as far as data goes, but it's going to make getting to the end of the table's column harder. 就数据而言,这是可以的,但是这会使到达表列末尾的难度加大。

I know I'm going to need to list out which columns go where for each column. 我知道我将需要列出每个列的哪一列。 In sheet1 there are 36 columns. 在sheet1中有36列。 In sheet 2 there are 49. This is perfectly acceptable. 在工作表2中有49。这是完全可以接受的。

Any guidance would be greatly appreciated. 任何指导将不胜感激。 It takes an insane amount of time to do this manually and I'm just trying to speed it up. 手动执行此操作需要耗费大量时间,而我只是想加快速度。 If it's easier to get everything to compile on sheet3, that's fine. 如果使所有内容都可以在sheet3上编译更容易,那很好。

Here is what I have so far, but it's not liking the stacking part. 到目前为止,这是我所拥有的,但是它不喜欢堆叠部分。

Sub Stacker()

'Select Full Report Sheet
Sheets("Full Report").Select

'Find Notes column and copy
Cells.find(What:="Notes", After:=Range("A1"), _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows).EntireColumn.Copy

'Select Secondary Report sheet, column E and paste
Sheets("Secondary Report").Select
Range("E1").Select
ActiveSheet.Paste
Application.CutCopyMode = False

End Sub

Thank you 谢谢

I've previously written code that lets you mash all your data from seperate tables into one table, no matter the order of the columns. 我之前已经编写了代码,无论列的顺序如何,您都可以将所有数据从单独的表混搭到一个表中。 See https://stackoverflow.com/a/47279374/2507160 参见https://stackoverflow.com/a/47279374/2507160

I'd also suggest trying out PowerQuery to do the same. 我也建议尝试使用PowerQuery进行相同的操作。 See https://stackoverflow.com/a/47170312/2507160 参见https://stackoverflow.com/a/47170312/2507160

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM