VBAToolMaker
New Member
- Joined
- Nov 19, 2013
- Messages
- 5
Version: Excel 2010
My main spreadsheet is to consolidate specific month of information from regional office spreadsheets, containing tables with multiple month data in different tabs. I want to either sort & copy or filter & copy from the regional office spreadsheets. The driving macro is in the main spreadsheet.
My issue has to do with not successfully activating the open regional office spreadsheet in order to define the variable range in order to either sort or filter.
I have tried two different methods, where both receive errors but different ones.
Option 1: Sheet9.Select (Object Required error)
Option 2: Workbooks(tROWorkbookName).Sheet9.Select (Error 438 "Object does not support this property or method")
I am still trouble shooting the draft module and am at the stage shown in the excerpt below. The present version shows option 1.
Private Sub UploadMonthlyData()
ChDir tSourceDataFilePath
'File Parameters
nFilePathCol = 1
nFileNameCol = 2
nFileRow = 2
Windows(tMainWorkbookName).Activate
Sheet10.Range("A2").Select
tFilepath = Cells(nFileRow, nFilePathCol).Value
tFileName = Cells(nFileRow, nFileNameCol).Value
nLengthFilePath = Len(tFilepath)
nLengthFileName = Len(tFileName)
tFilePathWoName = Left(tFilepath, nLengthFilePath - nLengthFileName)
tMainReportMonth = Range("MONTHREPORT").Value
Do While tFilepath <> "" 'Going from top to bottom of the list of files within the provincial tool
'////// Opening each file without updating links
Set wb2 = Workbooks.Open(tFilepath, False, False)
tROWorkbookName = wb2.Name
Workbooks(tMainWorkbookName).Activate
Sheet10.Select
Range("A2").Select
'////// UPLOAD DATA /////
nMainReferenceRow = 3
nIPMainDatabaseFirstRow = Range("IPDATABASEFIRSTRECORDROW").Value
nIPMainDatabaseLastRow = Range("IPDATABASELASTRECORD").Value
nIPMainReferenceDatabaseColumn = Range("IPREFERENCEUPLOADDATEDATABASECOLUMN").Value
tIPMainReferenceColumnName = Sheet6.Cells(nMainReferenceRow, nIPMainReferenceDatabaseColumn - 3).Value
wb2.Activate
With wb2
nIPRODatabaseFirstRow = Range("IPDATABASEFIRSTRECORDROW").Value
nIPRODatabseLastColumn = Range("IPDATABASELASTCOLUMN").Value
nIPRODatabaseReportMonthColumn = Range("IPDATABASEREPORTMONTHCOLUMN").Value
nIPRODatabaseUniqueChildIndexColumn = Range("IPDATABASEUNIQUECHILDINDEXCOLUMN").Value
nIPRODatabaseLastRow = Range("IPDATABASELASTRECORD").Value
End With
'//////Sort Database by report month and person
'//////'Important that exact same structure for both main and regional office files.
Workbooks(tROWorkbookName).Activate
Sheet9.Cells(nIPRODatabaseFirstRow, 1).Select
Set rIPDatabaseSortRange = Range(Sheet9.Cells(nIPRODatabaseFirstRow, 1), Sheet9.Cells(nIPRODatabaseLastRow, nIPRODatabseLastColumn))
With Sheet9.Sort
.SortFields.Clear
.SortFields.Add Key:= _
Cells(nIPMainDatabaseFirstRow, nIPRODatabaseReportMonthColumn), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
.SortFields.Add Key:= _
Cells(nIPMainDatabaseFirstRow, nIPRODatabaseUniqueChildIndexColumn), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
.SetRange rIPDatabaseSortRange
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.Apply
End With
My main spreadsheet is to consolidate specific month of information from regional office spreadsheets, containing tables with multiple month data in different tabs. I want to either sort & copy or filter & copy from the regional office spreadsheets. The driving macro is in the main spreadsheet.
My issue has to do with not successfully activating the open regional office spreadsheet in order to define the variable range in order to either sort or filter.
I have tried two different methods, where both receive errors but different ones.
Option 1: Sheet9.Select (Object Required error)
Option 2: Workbooks(tROWorkbookName).Sheet9.Select (Error 438 "Object does not support this property or method")
I am still trouble shooting the draft module and am at the stage shown in the excerpt below. The present version shows option 1.
Private Sub UploadMonthlyData()
ChDir tSourceDataFilePath
'File Parameters
nFilePathCol = 1
nFileNameCol = 2
nFileRow = 2
Windows(tMainWorkbookName).Activate
Sheet10.Range("A2").Select
tFilepath = Cells(nFileRow, nFilePathCol).Value
tFileName = Cells(nFileRow, nFileNameCol).Value
nLengthFilePath = Len(tFilepath)
nLengthFileName = Len(tFileName)
tFilePathWoName = Left(tFilepath, nLengthFilePath - nLengthFileName)
tMainReportMonth = Range("MONTHREPORT").Value
Do While tFilepath <> "" 'Going from top to bottom of the list of files within the provincial tool
'////// Opening each file without updating links
Set wb2 = Workbooks.Open(tFilepath, False, False)
tROWorkbookName = wb2.Name
Workbooks(tMainWorkbookName).Activate
Sheet10.Select
Range("A2").Select
'////// UPLOAD DATA /////
nMainReferenceRow = 3
nIPMainDatabaseFirstRow = Range("IPDATABASEFIRSTRECORDROW").Value
nIPMainDatabaseLastRow = Range("IPDATABASELASTRECORD").Value
nIPMainReferenceDatabaseColumn = Range("IPREFERENCEUPLOADDATEDATABASECOLUMN").Value
tIPMainReferenceColumnName = Sheet6.Cells(nMainReferenceRow, nIPMainReferenceDatabaseColumn - 3).Value
wb2.Activate
With wb2
nIPRODatabaseFirstRow = Range("IPDATABASEFIRSTRECORDROW").Value
nIPRODatabseLastColumn = Range("IPDATABASELASTCOLUMN").Value
nIPRODatabaseReportMonthColumn = Range("IPDATABASEREPORTMONTHCOLUMN").Value
nIPRODatabaseUniqueChildIndexColumn = Range("IPDATABASEUNIQUECHILDINDEXCOLUMN").Value
nIPRODatabaseLastRow = Range("IPDATABASELASTRECORD").Value
End With
'//////Sort Database by report month and person
'//////'Important that exact same structure for both main and regional office files.
Workbooks(tROWorkbookName).Activate
Sheet9.Cells(nIPRODatabaseFirstRow, 1).Select
Set rIPDatabaseSortRange = Range(Sheet9.Cells(nIPRODatabaseFirstRow, 1), Sheet9.Cells(nIPRODatabaseLastRow, nIPRODatabseLastColumn))
With Sheet9.Sort
.SortFields.Clear
.SortFields.Add Key:= _
Cells(nIPMainDatabaseFirstRow, nIPRODatabaseReportMonthColumn), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
.SortFields.Add Key:= _
Cells(nIPMainDatabaseFirstRow, nIPRODatabaseUniqueChildIndexColumn), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
.SetRange rIPDatabaseSortRange
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.Apply
End With