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

<colgroup><col style="width: 48pt;" span="3" width="64"> <tbody>
</tbody>
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
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,214,601
Messages
6,120,460
Members
448,965
Latest member
grijken

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