A
a
I'm having problems with the nesting. I want to open one file - pull
all of the information from the 45 sheets into a master file then close
the file and move on to the next file where I will pull the information
from the next file and put it into the appropriate sheet in the master file.
The files are listed on one sheet. The accounts are listed on another
sheet. My problem is that I seem to be nesting incorrectly. I can get
the first file to open, it then pulls all of the account information
into my master file and then I want it to close the file and move on to
the next file but instead it sees that the account information is empty
and I get an error.
I am not sure how to get around this. Can anybody help me with this? I
can get the same result using an array for the rollups but then it opens
1 file pulls the information for 1 account and then closes the file and
opens the next file - looping through the files and populating by account.
Below is the code - I know that it is convoluted but I was hoping
somebody could help me with the nasty loop issue so that I could clean
things up.
Thanks in advance for any help that you can give.
Regards,
anita
Sub engTest()
Dim bookList
Dim i
tablerow1 = 1
tablerow = 1
i = 1
Workbooks("New Sales Attempt.xls").Worksheets("summary").Activate
Workbooks("New Sales Attempt.xls").Worksheets("summary").Unprotect
password:="nope"
Cells.Select
Selection.Clear
If theRolluplevel = "ttleuropesale" Then
myCC = Workbooks("New Sales
Attempt.xls").Sheets("ttls").Cells(tablerow, z)
ElseIf theRolluplevel = "ttlasiansale" Then
myCC = Workbooks("New Sales
Attempt.xls").Sheets("ttls").Cells(tablerow, z)
ElseIf theRolluplevel = "ttljapansale" Then
myCC = Workbooks("New Sales
Attempt.xls").Sheets("ttls").Cells(tablerow, z)
ElseIf theRolluplevel = "ttlsalesadmin" Then
myCC = Workbooks("New Sales
Attempt.xls").Sheets("ttls").Cells(tablerow, z)
Else: theRolluplevel = "ttlslseng"
myCC = Workbooks("New Sales
Attempt.xls").Sheets("ttls").Cells(tablerow, z)
End If
Do Until myCC = ""
Workbooks.Open myCC, updatelinks:=False
theSelectedNotePad = Workbooks("New Sales
Attempt.xls").Sheets("accounts").Cells(tablerow1, 1)
Do Until theSelectedNotePad = ""
theSelectedNotePad = Workbooks("New Sales
Attempt.xls").Sheets("accounts").Cells(tablerow1, 1)
Set rng = Workbooks("New Sales
Attempt.xls").Worksheets("Summary").Range("A1")
Set rng = Workbooks("New Sales Attempt.xls") _
..Worksheets("summary").Range("A1")
theRollupLevel1 = theRolluplevel & ".xls"
rng.Parent.Parent.Activate
rng.Parent.Activate
'Resets the workbook
rng.Select
ActiveSheet.Unprotect
ActiveSheet.PageSetup.PrintArea = ""
Application.ScreenUpdating = False
Columns("A:t").Select
Range("U1").Activate
Selection.Clear
Selection.EntireRow.Hidden = False
'initializes the workbook in the array
'Opens the source book in the array
Application.StatusBar = "processing " & myCC & " " & theSelectedNotePad
Workbooks(myCC).Activate
Workbooks(myCC).Activate
Sheets(theSelectedNotePad).Select
ActiveSheet.Unprotect ("nope")
'hardcodes linked cells
Columns("a:b").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
ActiveSheet.Paste
Application.CutCopyMode = False
'Sets the range that will be copied to the summary sheet
Set rng1 = Workbooks(myCC).Worksheets(theSelectedNotePad).Range("A1:t59")
rng1.Select
'Copies the information from the source book to the summary file
i = 1
rng1.Copy Destination:=rng((i - 1) * 59 + 1).Offset(0, 1)
'determines the number of rows that will be used in the next part of the
procedure
j = i * 60
k = 0 - j
l = 5 + j
'increments number of workbooks to multiply by number of rows in notepad
'ActiveWorkbook.Close SaveChanges:=False
Workbooks(myNotePadSummary).Sheets(theSelectedNotePad).Delete
Workbooks("New Sales Attempt.xls").Sheets("Summary").Copy
Before:=Workbooks(myNotePadSummary).Sheets("template")
ActiveSheet.DrawingObjects.Select
Selection.Delete
Application.CutCopyMode = False
'selects the first cell in the range that will determine whether the row
should be hidden
Sheets("Summary").Name = theSelectedNotePad
tablerow1 = tablerow1 + 1
Loop
Workbooks(myCC).Close savechanges:=False
tablerow = tablerow + 1
myCC = Workbooks("New Sales
Attempt.xls").Sheets("ttls").Cells(tablerow, z)
Loop
end sub
all of the information from the 45 sheets into a master file then close
the file and move on to the next file where I will pull the information
from the next file and put it into the appropriate sheet in the master file.
The files are listed on one sheet. The accounts are listed on another
sheet. My problem is that I seem to be nesting incorrectly. I can get
the first file to open, it then pulls all of the account information
into my master file and then I want it to close the file and move on to
the next file but instead it sees that the account information is empty
and I get an error.
I am not sure how to get around this. Can anybody help me with this? I
can get the same result using an array for the rollups but then it opens
1 file pulls the information for 1 account and then closes the file and
opens the next file - looping through the files and populating by account.
Below is the code - I know that it is convoluted but I was hoping
somebody could help me with the nasty loop issue so that I could clean
things up.
Thanks in advance for any help that you can give.
Regards,
anita
Sub engTest()
Dim bookList
Dim i
tablerow1 = 1
tablerow = 1
i = 1
Workbooks("New Sales Attempt.xls").Worksheets("summary").Activate
Workbooks("New Sales Attempt.xls").Worksheets("summary").Unprotect
password:="nope"
Cells.Select
Selection.Clear
If theRolluplevel = "ttleuropesale" Then
myCC = Workbooks("New Sales
Attempt.xls").Sheets("ttls").Cells(tablerow, z)
ElseIf theRolluplevel = "ttlasiansale" Then
myCC = Workbooks("New Sales
Attempt.xls").Sheets("ttls").Cells(tablerow, z)
ElseIf theRolluplevel = "ttljapansale" Then
myCC = Workbooks("New Sales
Attempt.xls").Sheets("ttls").Cells(tablerow, z)
ElseIf theRolluplevel = "ttlsalesadmin" Then
myCC = Workbooks("New Sales
Attempt.xls").Sheets("ttls").Cells(tablerow, z)
Else: theRolluplevel = "ttlslseng"
myCC = Workbooks("New Sales
Attempt.xls").Sheets("ttls").Cells(tablerow, z)
End If
Do Until myCC = ""
Workbooks.Open myCC, updatelinks:=False
theSelectedNotePad = Workbooks("New Sales
Attempt.xls").Sheets("accounts").Cells(tablerow1, 1)
Do Until theSelectedNotePad = ""
theSelectedNotePad = Workbooks("New Sales
Attempt.xls").Sheets("accounts").Cells(tablerow1, 1)
Set rng = Workbooks("New Sales
Attempt.xls").Worksheets("Summary").Range("A1")
Set rng = Workbooks("New Sales Attempt.xls") _
..Worksheets("summary").Range("A1")
theRollupLevel1 = theRolluplevel & ".xls"
rng.Parent.Parent.Activate
rng.Parent.Activate
'Resets the workbook
rng.Select
ActiveSheet.Unprotect
ActiveSheet.PageSetup.PrintArea = ""
Application.ScreenUpdating = False
Columns("A:t").Select
Range("U1").Activate
Selection.Clear
Selection.EntireRow.Hidden = False
'initializes the workbook in the array
'Opens the source book in the array
Application.StatusBar = "processing " & myCC & " " & theSelectedNotePad
Workbooks(myCC).Activate
Workbooks(myCC).Activate
Sheets(theSelectedNotePad).Select
ActiveSheet.Unprotect ("nope")
'hardcodes linked cells
Columns("a:b").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
ActiveSheet.Paste
Application.CutCopyMode = False
'Sets the range that will be copied to the summary sheet
Set rng1 = Workbooks(myCC).Worksheets(theSelectedNotePad).Range("A1:t59")
rng1.Select
'Copies the information from the source book to the summary file
i = 1
rng1.Copy Destination:=rng((i - 1) * 59 + 1).Offset(0, 1)
'determines the number of rows that will be used in the next part of the
procedure
j = i * 60
k = 0 - j
l = 5 + j
'increments number of workbooks to multiply by number of rows in notepad
'ActiveWorkbook.Close SaveChanges:=False
Workbooks(myNotePadSummary).Sheets(theSelectedNotePad).Delete
Workbooks("New Sales Attempt.xls").Sheets("Summary").Copy
Before:=Workbooks(myNotePadSummary).Sheets("template")
ActiveSheet.DrawingObjects.Select
Selection.Delete
Application.CutCopyMode = False
'selects the first cell in the range that will determine whether the row
should be hidden
Sheets("Summary").Name = theSelectedNotePad
tablerow1 = tablerow1 + 1
Loop
Workbooks(myCC).Close savechanges:=False
tablerow = tablerow + 1
myCC = Workbooks("New Sales
Attempt.xls").Sheets("ttls").Cells(tablerow, z)
Loop
end sub