LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Help with For Next and Exit For

I have the following syntax which runs a For Each Next loop. This works
absolutely fine but I'd now like to introduce another sub called
Hierarchies_Check (this is essentially the same data check but on a different
worksheet) only if the code passes through the For Each statement without
finding any exceptions. I have an Exit For statement to quit the routine
(which allows the user to make the corrections one at a time rather than
being inundated with msgbox after msgbox if several exceptions are found).
I understand the Exit For will transfer control to the statement following
the Next statement therefore if I insert Hierarchies_Check sub after the Next
myCell line it will run the next routine before I'd like it to. I would
like the first For Each loop to be satisfied on the first worksheet before it
moves to the next worksheet to check. Can anyone suggest a workaround my code
is below.
Many thanks
Jacqui
PS Thank you to everyone who has helped me compile the code so far, you know
who you are so thanks for your input.

Option Explicit

Public myCell As Range
Public myRng As Range
Public wks As Worksheet
Public myRngToCheck As Range

Sub Qualifiers_Check()

Set wks = ActiveWorkbook.Worksheets("Part B - Coding Details")

With wks

Set myRng = .Range("c20", .Cells(.Rows.Count, "c").End(xlUp))

Set myRng = myRng.Resize(myRng.Count - 1)

For Each myCell In myRng.Cells
If IsEmpty(myCell.Value) = False And Not myCell.Font.Bold Then
Set myRngToCheck = .Cells(myCell.Row, "k").Resize(1, 5)
If Application.CountA(myRngToCheck) < myRngToCheck.Cells.Count
Then
Beep

Msgbox "You have not supplied all the relevant information
for this Segment type in Row " _
& myCell.Row & " on the Coding Details Sheet -
PLEASE ENTER ALL DETAILS" _
, 48, "Change Request Form Error Checks - SECTIONS A - E"

Worksheets("Part B - Coding Details").Select
myCell.Select

Exit For

End If
End If
Next myCell

'Hierarchies_Check (doesn't run in the right place)


End With


End Sub

Sub Hierarchies_Check()

Set wks = ActiveWorkbook.Worksheets("Part C - Hierarchies")


With wks

Set myRng = .Range("c20", .Cells(.Rows.Count, "c").End(xlUp))

Set myRng = myRng.Resize(myRng.Count - 1)

For Each myCell In myRng.Cells
If IsEmpty(myCell.Value) = False And Not myCell.Font.Bold Then
Set myRngToCheck = .Cells(myCell.Row, "l").Resize(1, 4)
If Application.CountA(myRngToCheck) < myRngToCheck.Cells.Count
Then
Beep

Msgbox "You have not supplied all the relevant information
for this Segment type in Row " _
& myCell.Row & " on the Coding Details Sheet -
PLEASE ENTER ALL DETAILS" _
, 48, "Change Request Form Error Checks - SECTION F
HIERARCHIES"

Worksheets("Part C - Hierarchies").Select

myCell.Select


Exit For

End If
End If
Next myCell

End With


End Sub





 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exit Sub Jeff Excel Discussion (Misc queries) 2 March 1st 08 06:21 PM
Run when exit PH NEWS Excel Worksheet Functions 1 July 18th 06 03:53 PM
exit while? Steven Deng Excel Programming 1 November 6th 04 12:14 AM
Exit when its a Mac Tushar Mehta Excel Programming 0 September 21st 04 03:41 PM
If a called sub exit, how to the caller exit right away? luvgreen[_4_] Excel Programming 4 February 24th 04 05:06 PM


All times are GMT +1. The time now is 02:39 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"