Computerman
Board Regular
- Joined
- Mar 3, 2016
- Messages
- 91
I have one workbook that contains one sheet that is a pivot table of a sharepoint page. The workbook keeps track of sites that are being worked every day, and the technicians that are doing the work. It mainly keeps track of sites that have not started yet, Scheduled. Sites that have a tech working, In Progress. Sites that are finished, Complete. And sites that are not able to be completed, Reschedule. I have a second workbook that I use to keep track of the deliverables that the techs are required to send in during the course of the work. What I want to do is use the status field in the ‘sharepoint’ workbook to control certain actions in the ‘deliverables’ workbook.
The code I have created is:
Private Sub cmdRefresh_Click()
Dim x As Integer
Dim y As Integer
Dim lastrow As Long
Dim Status As String
'Refesh the table the data is pulled from:
ThisWorkbook.RefreshAll
'determine the last row of the pivot table
lastrow = Sheet1.Range("A65536").End(xlUp).Row
For x = 9 To lastrow
y = x - 6
Status = Sheet1.Range("C" & x).Value
Select Case Status
Case "Scheduled"
Workbooks.Open Filename:="Darden Picture Status.xlsm"
Workbooks("Darden Picture Status.xlsm").Sheets("Sheet1").Range("K" & y).Interior.ColorIndex = 33
Workbooks("Darden Picture Status.xlsm").Save
Case "Complete"
'Workbooks.Open Filename:="C:\Users\webbmart\Documents\VBA\Darden Picture Status.xlsm"
Workbooks("C:\Users\webbmart\Documents\VBA\Darden Picture Status.xlsm").Activate
Workbooks("C:\Users\webbmart\Documents\VBA\Darden Picture Status.xlsm").Sheets("Sheet1").Range("J" & y).Value = "X"
Workbooks("C:\Users\webbmart\Documents\VBA\Darden Picture Status.xlsm").Sheets("Sheet1").Range("K" & y).Interior.ColorIndex = 14
Workbooks("C:\Users\webbmart\Documents\VBA\Darden Picture Status.xlsm").Save
Case "Reschedule"
Workbooks.Open Filename:="Darden Picture Status.xlsm"
Workbooks("Darden Picture Status.xlsm").Sheets("Sheet1").Range("J" & y).Value = "R"
Workbooks("Darden Picture Status.xlsm").Save
Case "In Progress"
Workbooks.Open Filename:="Darden Picture Status.xlsm"
Workbooks("Darden Picture Status.xlsm").Sheets("Sheet1").Range("K" & y).Interior.ColorIndex = 48
Workbooks("Darden Picture Status.xlsm").Save
End Select
Next x
End Sub
In testing this code I get the error “Run-time error ‘9’: Subscript out of range.” When the code gets to the line: Workbooks("C:\Users\webbmart\Documents\VBA\Darden Picture Status.xlsm").Activate in the Complete case above.
I have placed a stop on the Select Case statement and used F8 to step through the code. It fails at the first instance of accessing the Darden Picture Status.xlsm line.
As a side note I tested this code on a pair of workbooks and know that it does work, the only difference is that the test workbooks have one word names with no spaces, where my working workbooks have multiple word names with spaces. I have carefully gone over the workbook names to be sure that I am not missing a space or any other misspelling. I have been going over the code and googling the error for the past week with no luck. The code is initiated by a command button on the 'sharepoint' workbook.
Has anyone seen this type of error in this scenario?
Thank you,
Computerman
The code I have created is:
Private Sub cmdRefresh_Click()
Dim x As Integer
Dim y As Integer
Dim lastrow As Long
Dim Status As String
'Refesh the table the data is pulled from:
ThisWorkbook.RefreshAll
'determine the last row of the pivot table
lastrow = Sheet1.Range("A65536").End(xlUp).Row
For x = 9 To lastrow
y = x - 6
Status = Sheet1.Range("C" & x).Value
Select Case Status
Case "Scheduled"
Workbooks.Open Filename:="Darden Picture Status.xlsm"
Workbooks("Darden Picture Status.xlsm").Sheets("Sheet1").Range("K" & y).Interior.ColorIndex = 33
Workbooks("Darden Picture Status.xlsm").Save
Case "Complete"
'Workbooks.Open Filename:="C:\Users\webbmart\Documents\VBA\Darden Picture Status.xlsm"
Workbooks("C:\Users\webbmart\Documents\VBA\Darden Picture Status.xlsm").Activate
Workbooks("C:\Users\webbmart\Documents\VBA\Darden Picture Status.xlsm").Sheets("Sheet1").Range("J" & y).Value = "X"
Workbooks("C:\Users\webbmart\Documents\VBA\Darden Picture Status.xlsm").Sheets("Sheet1").Range("K" & y).Interior.ColorIndex = 14
Workbooks("C:\Users\webbmart\Documents\VBA\Darden Picture Status.xlsm").Save
Case "Reschedule"
Workbooks.Open Filename:="Darden Picture Status.xlsm"
Workbooks("Darden Picture Status.xlsm").Sheets("Sheet1").Range("J" & y).Value = "R"
Workbooks("Darden Picture Status.xlsm").Save
Case "In Progress"
Workbooks.Open Filename:="Darden Picture Status.xlsm"
Workbooks("Darden Picture Status.xlsm").Sheets("Sheet1").Range("K" & y).Interior.ColorIndex = 48
Workbooks("Darden Picture Status.xlsm").Save
End Select
Next x
End Sub
In testing this code I get the error “Run-time error ‘9’: Subscript out of range.” When the code gets to the line: Workbooks("C:\Users\webbmart\Documents\VBA\Darden Picture Status.xlsm").Activate in the Complete case above.
I have placed a stop on the Select Case statement and used F8 to step through the code. It fails at the first instance of accessing the Darden Picture Status.xlsm line.
As a side note I tested this code on a pair of workbooks and know that it does work, the only difference is that the test workbooks have one word names with no spaces, where my working workbooks have multiple word names with spaces. I have carefully gone over the workbook names to be sure that I am not missing a space or any other misspelling. I have been going over the code and googling the error for the past week with no luck. The code is initiated by a command button on the 'sharepoint' workbook.
Has anyone seen this type of error in this scenario?
Thank you,
Computerman