run time error 1004 in macro when copying data from various workbook sheets into one workbook sheet

HK0506

New Member
Joined
Sep 4, 2012
Messages
17
[TABLE="width: 144"]
<colgroup><col style="width: 48pt;" span="3" width="64"> <tbody>[TR]
[TD="width: 128, bgcolor: transparent, colspan: 2"]Hi

I am gettin a run time error when trying to use the below macro in VBA. It opens the file but then doesnt do anything else and returns me the error message.

Sub Macro3()
[/TD]
[TD="width: 64, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, colspan: 3"]Dim qfile(), i As Integer[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, colspan: 3"]Dim thiswb As Workbook, datawb As Workbook[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, colspan: 3"]Dim qrow As Integer[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, colspan: 3"]Set thiswb = ActiveWorkbook[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, colspan: 3"]Sheets("Sheet1").Range("A2").Select[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, colspan: 3"]qfile = Array("G:\Finance, Performance & Business Planning\Management Accounts\2015 Budget\Working templates\1st Issue\Business Development.*", _[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, colspan: 3"] "G:\Finance, Performance & Business Planning\2012_Business Planning\3 yr Budget & planning\2013 budgets and plans\Budgets Received\Customer engagement.*")[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, colspan: 3"] For i = O To UBound(qfile)[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, colspan: 3"] Workbooks.Open Filename:=qfile(i), ReadOnly:=True[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, colspan: 3"] Set datawb = ActiveWorkbook[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, colspan: 3"] Sheets("Sheet1").Select[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, colspan: 3"] qrow = Cells(Rows.Count, 1).End(xlUp).Row[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, colspan: 3"] Range("A7").Select[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, colspan: 3"] Do Until ActiveCell.Row = qrow[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, colspan: 3"] If ActiveCell.Value <> "" Then[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, colspan: 3"] ActiveCell.EntireRow.Copy[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, colspan: 3"] thiswb.Activate[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, colspan: 3"] ActiveCell.PasteSpecial xlPasteValues[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, colspan: 3"] ActiveCell.Offset(1, 0).Select[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, colspan: 3"] datawb.Activate[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, colspan: 3"] ActiveCell.Offset(1, 0).Select[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, colspan: 2"] Else[/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, colspan: 3"] ActiveCell.Offset(1, 0).Select[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, colspan: 2"] End If[/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"] Loop[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, colspan: 3"] datawb.Close SaveChanges:=False[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]Next i[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]End Sub[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
I see an error with this line:
Code:
[COLOR=#000000][FONT=Calibri]For i = O To UBound(qfile)[/FONT][/COLOR]
it should be the number 0, not the letter O, i.e.
Code:
[COLOR=#000000][FONT=Calibri]For i = 0 To UBound(qfile)[/FONT][/COLOR]
 
Upvote 0

Forum statistics

Threads
1,225,761
Messages
6,186,893
Members
453,383
Latest member
SSXP

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top