From: Eric on
The following coding works fine, but once I change following code

"If CStr(d.Value) = ws.Name Then DelFlag = False"
into
"If CStr(d.Value) = ws.Name Then "
"DelFlag = False"
I would like to do it, so during the debugging process, I can see whether
this line is proceeded or not.
It pops up a message about Next without For,
Does anyone have any suggestions on where is the problem?

For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Date" Then
For Each d In MyRange
If CStr(d.Value) = ws.Name Then DelFlag = False
Exit For
End If
Next
If DelFlag Then
ws.Delete
End If
DelFlag = True
Next
From: macropod on
hi Eric,

The problem is here:
If CStr(d.Value) = ws.Name Then DelFlag = False
Exit For
End If
It should be:
If CStr(d.Value) = ws.Name Then
DelFlag = False
Exit For
End If


--
Cheers
macropod
[Microsoft MVP - Word]


"Eric" <Eric(a)discussions.microsoft.com> wrote in message news:76453C92-2F12-496C-8C21-149D9B85FAAA(a)microsoft.com...
> The following coding works fine, but once I change following code
>
> "If CStr(d.Value) = ws.Name Then DelFlag = False"
> into
> "If CStr(d.Value) = ws.Name Then "
> "DelFlag = False"
> I would like to do it, so during the debugging process, I can see whether
> this line is proceeded or not.
> It pops up a message about Next without For,
> Does anyone have any suggestions on where is the problem?
>
> For Each ws In ThisWorkbook.Worksheets
> If ws.Name <> "Date" Then
> For Each d In MyRange
> If CStr(d.Value) = ws.Name Then DelFlag = False
> Exit For
> End If
> Next
> If DelFlag Then
> ws.Delete
> End If
> DelFlag = True
> Next
From: RonaldoOneNil on
When your if statement is in one line you can only have one statement
following the Then and you cannot have an End IF

Your code has to be like this
If CStr(d.Value) = ws.Name Then
DelFlag = False
Exit For
End If



"Eric" wrote:

> The following coding works fine, but once I change following code
>
> "If CStr(d.Value) = ws.Name Then DelFlag = False"
> into
> "If CStr(d.Value) = ws.Name Then "
> "DelFlag = False"
> I would like to do it, so during the debugging process, I can see whether
> this line is proceeded or not.
> It pops up a message about Next without For,
> Does anyone have any suggestions on where is the problem?
>
> For Each ws In ThisWorkbook.Worksheets
> If ws.Name <> "Date" Then
> For Each d In MyRange
> If CStr(d.Value) = ws.Name Then DelFlag = False
> Exit For
> End If
> Next
> If DelFlag Then
> ws.Delete
> End If
> DelFlag = True
> Next
 | 
Pages: 1
Prev: Code to adjust column width
Next: Userform Layout