Workbook Coding Effecting other workbooks

sassriverrat

Well-known Member
Joined
Oct 4, 2018
Messages
655
I have a workbook that seems to cause errors with other workbooks. It seems random but usually the error is 9- subscript out of range

Ideas on this? Here's an example of code that kicked when I opened another workbook

Code:
Function PrevSheet(RCell As Range)

'Begins Error Handling Code
On Error GoTo Helper


    Dim xIndex As Long
    Application.Volatile
    xIndex = RCell.Worksheet.Index
    If xIndex > 1 Then
        PrevSheet = Worksheets(xIndex - 1).Range(RCell.Address)
    End If
    
'Error Clearing Code
Exit Function
Helper:
    resp = MsgBox("We're sorry to see you've encountered an error." & vbCrLf & vbCrLf & "To proceed, we recommend you contact the Developer " & _
    "with error codes [1141] and " & "[" & Err.Number & "-" & Err.Description & "]." & vbCrLf & vbCrLf & "To attempt to patch your problem at least " & _
    "temporarily, we recommend you click [Yes] to see help directions. Would you like to continue?", vbYesNoCancel, name)
        If resp = vbYes Then
            UserForm18.Show
            'MsgBox ("Success")
        ElseIf resp = vbNo Then
            Exit Function
        ElseIf resp = vbCancel Then
            Exit Function
        End If
End Function
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
My guess is that Worksheets(xIndex-1) isn't qualified.

Try

Code:
PrevSheet = RCell.Parent.Parent.Worksheets(xIndex-1).Range(RCell.Address).Value
 
Last edited:
Upvote 0
I’ll give that a shot. I was working with another member in the forum on this and didn’t mean to repeat this post, but the other suggestion hadn’t worked.

If you have a second, purely for my learning, what does it mean above to not be qualified?
 
Upvote 0
The OP code does not specify which workbook's Worksheets collection is to be used. This is called "unqualified".By default, the ActiveWorkbook is used.
Code:
PrevSheet = Worksheets(xIndex - 1).Range(RCell.Address)
The code in post #2 specifies that the Worksheets collection of the same workbook as RCell is to be used. This is called "qualifying" one's code.

Code:
PrevSheet = RCell.Parent.Parent.Worksheets(xIndex-1).Range(RCell.Address).Value
 
Upvote 0
The OP code does not specify which workbook's Worksheets collection is to be used. This is called "unqualified".By default, the ActiveWorkbook is used.
Code:
PrevSheet = Worksheets(xIndex - 1).Range(RCell.Address)
The code in post #2 specifies that the Worksheets collection of the same workbook as RCell is to be used. This is called "qualifying" one's code.

Code:
PrevSheet = RCell.Parent.Parent.Worksheets(xIndex-1).Range(RCell.Address).Value


Excellent. That makes sense. I'll play with it and see if any errors are induced!
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,161
Members
453,021
Latest member
Justyna P

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