Out of Stack space - run time error 28

R

Rob

I am trying to run a macro in Excel and keep running out of Stack space can
anyone see what is wrong (probably a lot) with this macro.

Sub Macro2()
'
' Macro2 Macro
' Macro recorded 17/12/2007 by RLamb2
'

'
Range("A2").Select
Application.Run "'Export from APC.xls'!Changelength"
End Sub

Sub Changelength()

If Len(ActiveCell) = 0 Then
Application.Run "'Export from APC.xls'!Extractdate"
End If
If Len(ActiveCell) = 4 Then
Selection.Offset(1, 0).Select
End If
If Len(ActiveCell) = 3 Then
ActiveCell.Formula = "'0" & ActiveCell.Formula
End If
Selection.Offset(1, 0).Select
Application.Run "'Export from APC.xls'!Checklength"

End Sub
 
J

Jim Rech

The sub can't just keep calling itself. Check your logic.

Sub CallMe()
CallMe
End Sub

--
Jim
|I am trying to run a macro in Excel and keep running out of Stack space can
| anyone see what is wrong (probably a lot) with this macro.
|
| Sub Macro2()
| '
| ' Macro2 Macro
| ' Macro recorded 17/12/2007 by RLamb2
| '
|
| '
| Range("A2").Select
| Application.Run "'Export from APC.xls'!Changelength"
| End Sub
|
| Sub Changelength()
|
| If Len(ActiveCell) = 0 Then
| Application.Run "'Export from APC.xls'!Extractdate"
| End If
| If Len(ActiveCell) = 4 Then
| Selection.Offset(1, 0).Select
| End If
| If Len(ActiveCell) = 3 Then
| ActiveCell.Formula = "'0" & ActiveCell.Formula
| End If
| Selection.Offset(1, 0).Select
| Application.Run "'Export from APC.xls'!Checklength"
|
| End Sub
 
J

Jim Thomlinson

What is your stopping criteria. There is nothing that stops this from
running. You have an infinite loop. As guess you are trying to loop through
all of the cells in Column A until you run out of data. If that is the case
then try somethying more like this...

sub WhatEver()
dim rng as range
dim rngToSearch as Range

set rngtosearch = range(range("A2"), cells(rows.count, "A").end(xlup))

for each rng in rngtosearch
with rng
select len(rng)
case 0
call extractdate
case 3
rng.formula = "'0" & rng.formula
end select
end with
next rng
end sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top