Greetings. Gurus.
I'm working with a large master list of part numbers, and matching data to these numbers from a varying data table via vlookup. I have to vlookup to the actual part number, (13,000 numbers), then subtotal the data based on the "Rollup" part number. (eg: Two different old PNs have now "rolled up" into a single part number. I am pulling sales data from all of the old numbers, and subtotaling the sales to the new number.) Too much information.
Here's my issue. After subtotaling on the rollup number, I want to copy and paste ONLY the rollup numbers and associated data to a different sheet. This should be easily accomplished by going to level 2 of the subtotals page, hiding all the old PNs and their data, selecting the remaining visible cells, then "Go To", "Special", "Visible cells". Normally, you could copy only the visible cells, and paste them wherever you want. But because of the total length of the subtotaled worksheet, (nearly 25,000 rows), I get the error message, "Micrsoft Excel cannot create or use the data range reference because it is too complex."
You can overcome this by selecting smaller ranges of data, and copying and pasting a little at a time, but since the "visible rows" will vary, I can't figure a way to incorporate this into a macro. I've tried setting specific ranges in the macro, and copying and pasting fewer cell at a time, but if the range named in the macro is a hidden cell, the macro won't select any of them.
Here's an example of what I've got so far. I realize it's not the most efficient code, but I'm working with limited knowledge and ability.
Sub Paste_Subtotals()
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Selection.Subtotal GroupBy:=2, Function:=xlSum, TotalList:=Array(3, 4, 5, 6, _
7), Replace:=True, PageBreaks:=False, SummaryBelowData:=True
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveSheet.Outline.ShowLevels RowLevels:=2
Range("B1:G6000").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Subtotals").Select
Range("A1").Select
ActiveSheet.Paste
Range("B6001:G12500").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Subtotals").Select
Range("A1").Select
Selection.End(xlDown).Select
Selection.Offset(1, 0).Select
ActiveSheet.Paste
End Sub
I would have to repeat the copy and paste 4 times to get the full list of parts and data, which isn't a problem if I know it will select the right cells each time, but I'm open for other suggestions as well.
Sorry such a long post. Any help would be greatly appreciated.
Jerry
Bookmarks