System 13 Error

James_Latimer

Active Member
Joined
Jan 20, 2009
Messages
415
Excel 2003

Hello, i have a very strange issue that i cant get my head around. If someone could give me some pointers it would be much appreciated.

The following code is flagging the error...

Rich (BB code):
Sub maxPSA()
Dim TVal
Dim Cnt
Dim sh As Worksheet: Set sh = Sheets("PSA_Summary")

Application.ScreenUpdating = False

For Cnt = 15 To 165
    If sh.Range("FH" & Cnt).Value = 1 Then
            TVal = sh.Range("$FI$" & Cnt).Value
        GoTo jd_End:
    End If
Next Cnt

Application.ScreenUpdating = True

jd_End:
PSA_graph (TVal)

End Sub

The line highlighted in bold is where the error occurs.

The sheet PSA_Summary does exist so i cant understand why this doesn't work. This doesn't happen on all machines!?!?!?!?!?!?!?!?!?!? Any ideas what may be causing this please?

Thanks to anyone who can help.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hello Andrew

The value is 0%

Just for future reference for myself, would an #N/A or something similar in that cell cause that issue or would the IF statement simply return a FALSE?
 
Upvote 0
If sh.Range("FH" & Cnt).Value contains an error (#NA, #Value, etc.) as a value, then that would throw an error in your code

Maybe try something like this...

Code:
Sub maxPSA()
    Dim TVal
    Dim Cnt
    Dim sh As Worksheet: Set sh = Sheets("PSA_Summary")
    
    Application.ScreenUpdating = False
    
    For Cnt = 15 To 165
        [COLOR="Red"]If Not IsError(sh.Range("FH" & Cnt).Value) Then[/COLOR]
            If sh.Range("FH" & Cnt).Value = 1 Then
                TVal = sh.Range("$G$" & Cnt).Value
                Exit For
            End If
        [COLOR="Red"]End If[/COLOR]
    Next Cnt
    
    Application.ScreenUpdating = True
    
jd_End:
    PSA_graph (TVal)

End Sub

Note: you could also use Exit For to break out of the For-Next loop.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,555
Members
452,928
Latest member
101blockchains

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