Out of stack error 28

Jay McClure 21 Reputation points
2022-07-22T11:49:29.263+00:00

HI,
I'm having a problem figuring out how to get rid of out of stack error 28.
so what I have is someone scan inventory the target address is AI1 and it should copy to AI2 and it would clear after that by pushing a button called line Tag.
I'm fairly new to VBA, Thanks for help

Private Sub Worksheet_Change(ByVal Target As Range)

On Error Resume Next

'Range("AH1").Select

If Not Application.Intersect(Target, Range("$AI$1")) Is Nothing Then---->this is what error highlight
Range("AI1").Select

sV = Trim(Range("AI2").Value)   'Scan Value  

For x = 3 To 306  
    cV = Range("C" & x).Value   'Check Value (Load Number)  
    If sV = 0 Then Exit Sub  
    If cV = sV Then  
        tV = Range("Y" & x).Value   'tag Count  
        tV = tV + 1  
        Range("Y" & x).Value = tV  
        x = 306  
    ElseIf x = 306 Then  
        MsgBox "Load Not Found", vbOKOnly, "SCAN ERROR"  
    End If  

Next x  

sV = ""  
Range("AI1").Select  
Range("AI1").ClearContents  

End If  

End Sub

Developer technologies | Visual Basic for Applications
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.6K Reputation points
    2022-07-22T12:06:28.43+00:00

    When you change the worksheet, try adding two special lines, for example:

    Application.EnableEvents = False  
    Range("Y" & x).Value = tV  
    Application.EnableEvents = True  
    

    Do it for Range("AI1").ClearContents too.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.