Thread: For Statement
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default For Statement


s = "problem Names: " & vbNewLine &
For Each nName In ActiveWorkbook.Names
If Len(nName.Name) < 8 Then
s = s & nName.Name & _
"' (" & Right(nName.RefersTo, Len(nName.RefersTo) - 1) _
& "). & vbNewLine
End If
Next nName
if len(s) 20
msgbox s & vbNewline & _
"The defined name must have 8 characters long and must be corrected " & _
"in order to proceed further.", vbCritical
End if
--
Regards,
Tom Ogilvy



"AccessHelp" wrote:

Good morning,

I have the code below, and the code works fine. However, the problem is the
code checks problem defined names and messages the user individually, and it
would not check the next defined name unless one is corrected.

For example, I have two problem defined names: "A000PPLE" and "O000RANGE".
The code would alert the user on "A000PPLE" first, and the code would not
alert the user on "O000RANGE" unless the defined name "A000PPLE" is
corrected.

Is there a way to change the code below to alert the user all the problem
defined names so that the user can write down all the problem defined names
all at once and does not have to wait for another one unless one is fixed?

Thanks.


For Each nName In ActiveWorkbook.Names
If Len(nName.Name) < 8 Then
MsgBox "Please check and correct the defined name '" & _
nName.Name & "' (" & Right(nName.RefersTo,
Len(nName.RefersTo) - 1) & "). " & _
"The defined name must have 8 characters long and must
be corrected " & _
"in order to proceed further.", vbCritical
GoTo TheEnd
End If
Next nName
GoTo NoErrors