Subscript Error when Activating Workbook

mcconnella

New Member
Joined
Jul 21, 2009
Messages
4
I have some code here that is meant to copy data from three different workbooks and consolidate it in one worksheet in a new workbook.

Here's a sample of the first part of the code:

Sub AutoConsolidateDealStatus2()
'Specify the start row for the New Workbook
Dim d
d = 2

'Maximum Amount of rows to search through in each sheet, including the New Workbook
Dim MaxRows
MaxRows = 60000

'Specify the name of the new workbook
newWorkbookName = "DealStatus"

'Create new workbook
Workbooks.Add
ActiveWorkbook.SaveAs Filename:="P:\Admin\Financials\2010\" & newWorkbookName & ".xlsx", _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

'Write column headers in new workbook
Range("A1").Value = "Deal#"
Range("b1").Value = "Deal Status"
Range("c1").Value = "Firm Date"
Range("d1").Value = "Receipt/Received Date"
Range("e1").Value = "Property Address"
Range("f1").Value = "Vendor/Landlord#"
Range("g1").Value = "Purchaser/Tenant"
Range("h1").Value = "Associate"
Range("i1").Value = "Associate Commission"
Range("j1").Value = "Gross to Department"



'Copy Data from Pipeline workbook
currentWorkbook = "pipeline"
Workbooks.Open Filename:="P:\Admin\Financials\2010\Jan 25 Test\" & currentWorkbook & ".xls"
Windows(newWorkbookName).Activate

For i = 7 To MaxRows
If Not IsEmpty(Workbooks(currentWorkbook).Sheets("Sheet1").Range("A" & i)) Then

Range("A" & d).Value = Workbooks(currentWorkbook).Sheets("Sheet1").Range("D" & i) 'Deal Id
Range("B" & d).Value = Workbooks(currentWorkbook).Sheets("Sheet1").Range("B" & i) 'Deal Status
Range("D" & d).Value = Workbooks(currentWorkbook).Sheets("Sheet1").Range("C" & i) 'Expected Receipt Date/Received Date
Range("E" & d).Value = Workbooks(currentWorkbook).Sheets("Sheet1").Range("G" & i) 'Property Address
Range("F" & d).Value = Workbooks(currentWorkbook).Sheets("Sheet1").Range("H" & i) 'Vendor/Landlord
Range("G" & d).Value = Workbooks(currentWorkbook).Sheets("Sheet1").Range("I" & i) 'Purchaser/Tenant
Range("H" & d).Value = Workbooks(currentWorkbook).Sheets("Sheet1").Range("K" & i) 'Associate
Range("I" & d).Value = Workbooks(currentWorkbook).Sheets("Sheet1").Range("M" & i) 'Associate Commission
Range("J" & d).Value = Workbooks(currentWorkbook).Sheets("Sheet1").Range("N" & i) 'Gross to Department

d = d + 1

End If

Next i


I get an error everytime I run it at the Windows(newWorkbookName).Activate command. Subscript out of range error.

This code worked when I tested at home and now it's not working....can anyone help with why I'm getting the error.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
If Windows is set to display file extensions you'll need

Code:
newWorkbookName = "DealStatus.xlsx"
 
Upvote 0
Hmmm....so I just tried that modification and it doesn't work. Still the same error.

Thanks for the suggestion though!
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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