ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   macro not working (https://www.excelbanter.com/excel-discussion-misc-queries/68879-macro-not-working.html)

Jonathan Cooper

macro not working
 
ok...let me say up front, that I don't really know what I'm doing, but
everyone has to start somewhere. This is my first non-recorded macro.

I've created the following code. It seems to do what I want (because I can
watch what it's doing), except that it doesn't seem to END. I get an out of
stack space error. I'm sure this is some obvious mistake, but it eludes me.
Anyone know what i am doing wrong?

Sub eliminate_possabilities()

Dim solutions As Range
Dim cell As Range
Dim before As Integer

before = Range("BG31").Value

Set solutions = ActiveSheet.Range("AF3:BF29")
For Each cell In solutions
If cell.Value = 1 Then
cell.Offset(0, -30).ClearContents
Else:
End If
Next cell

Call CheckForChanges
End Sub

Sub CheckForChanges()

Dim after As Integer

after = Range("BG31").Value

If after before Then
Call eliminate_possabilities
Else:
End If
End Sub

Nick Hodge

macro not working
 
Jonathan

You do not need the Else: statements, but your issue is that the variable
'before' is not available to the second procedure as it is declared inside
the other module. Try moving the variable to the top of the module outside
of any sub that should fix it

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
www.nickhodge.co.uk


"Jonathan Cooper" wrote in
message ...
ok...let me say up front, that I don't really know what I'm doing, but
everyone has to start somewhere. This is my first non-recorded macro.

I've created the following code. It seems to do what I want (because I
can
watch what it's doing), except that it doesn't seem to END. I get an out
of
stack space error. I'm sure this is some obvious mistake, but it eludes
me.
Anyone know what i am doing wrong?

Sub eliminate_possabilities()

Dim solutions As Range
Dim cell As Range
Dim before As Integer

before = Range("BG31").Value

Set solutions = ActiveSheet.Range("AF3:BF29")
For Each cell In solutions
If cell.Value = 1 Then
cell.Offset(0, -30).ClearContents
Else:
End If
Next cell

Call CheckForChanges
End Sub

Sub CheckForChanges()

Dim after As Integer

after = Range("BG31").Value

If after before Then
Call eliminate_possabilities
Else:
End If
End Sub





All times are GMT +1. The time now is 11:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com