Out of Stack Space

lesleym

New Member
Joined
Jun 17, 2010
Messages
5
Can anyone help?!?!

The code below gives and Out of Stack Space error on the highlighted line. I've tried dimming the var at different levels incase that was the problem but it's not. This works in every other Sub in the workbook.

Any help would be appreciated.

Lesley

If Target.Address = "$B$5" Then
Dim ThisCell As String * 14
Dim MidValue As String * 1
ThisCell = Range("B5").Value
If ThisCell <> "" Then
MidValue = Mid(ThisCell, 9, 1)
If MidValue = "-" Then
ThisCell = UCase(ThisCell)
Range("B5").Value = ThisCell
Exit Sub
Else
ErrorStr = "Course code should be in the format XXXXXXXX-X101X"
ErrorBox (ErrorStr)
Range("B5").ClearContents
Range("B5").Select
End If
End If
Exit Sub
End If
 

Some videos you may like

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,079
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Are you doing this in a Change event? If so, you need to disable events as you are changing the cell value in your code and can end up stuck in a loop.
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
I think you are stuck in an infinite loop. Try turning off events

Code:
Dim ThisCell As String * 14
Dim MidValue As String * 1
If Target.Address = "$B$5" Then
    Application.EnableEvents = False
    ThisCell = Range("B5").Value
    If ThisCell <> "" Then
        MidValue = Mid(ThisCell, 9, 1)
        If MidValue = "-" Then
            ThisCell = UCase(ThisCell)
            Range("B5").Value = ThisCell
        Else
            ErrorStr = "Course code should be in the format XXXXXXXX-X101X"
            ErrorBox (ErrorStr)
            Range("B5").ClearContents
            Range("B5").Select
        End If
    End If
    Application.EnableEvents = True
End If
 

Watch MrExcel Video

Forum statistics

Threads
1,122,710
Messages
5,597,702
Members
414,164
Latest member
ARTW

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
Top