This code copies columns P & Q from each worksheet and posts them to a new worksheet consolidated. It also deletes all blank cells.
The code works on a very small file but isn't producing the same results on the new workbook.
ALL COLUMNS from previous "small workbook" to new workbook are the same. The only thing that changed is the number of worksheets which is 650.
I get a runtime error 429 "Activex component can't create object".
Sub merge()
Dim Sh As Worksheet, ShM As Worksheet, i&, z&
Application.ScreenUpdating = 0
Set Sh = Worksheets.Add(, Sheets(Sheets.Count))
Sh.Name = "consolidated"
For Each ShM In ThisWorkbook.Worksheets
If ShM.Name <> Sh.Name Then
i = ShM.Cells(Rows.Count, 17).End(xlUp).Row
z = Sh.Cells(Rows.Count, 2).End(xlUp).Row + 1
While (z > 1) And (Sh.Cells(z, 2).Value = "")
z = z - 1
Wend
ShM.Activate: ShM.Range(Cells(1, 16), Cells(i, 17)).Copy
Sh.Activate: Sh.Cells(z, 1).PasteSpecial xlPasteValues
End If
Next ShM
Application.ScreenUpdating = 1
End Sub
This error is not caused by the code you've posted, please see this: You receive run-time error 429 when you automate Office applications
also this issue has been discussed here:
Run-time error '429': ActiveX component can't create object VBA
check tools~>references for the missing components
I got the same issue 4 years later, my VBA code literally failed on the very first two lines:
Dim wb As Workbook
Set wb = ThisWorkbook
Same error if I use ?ThisWorkbook.name in the immediate window, etc. No matter what I do, I cannot use the "ThisWorkbook" object in this particular .xlsm
I created a brand new workbook, saved it as .xslm and copied the entire module to the new book, bingo, works perfectly.
There doesn't seem to be any difference between the new book I created and the old book that doesn't work...
tools->references are identical, they were saved on the same machine, same version of excel, etc etc.
It's just a bizzare issue that I can't figure out the cause of, in this particular Workbook, the "ThisWorkbook" function is broken. Re-creating the workbook from scratch seems to resolve it, but it's a poor solution.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.