PC Review


Reply
Thread Tools Rate Thread

alternative required; Fo Each Loop

 
 
WhytheQ
Guest
Posts: n/a
 
      17th Aug 2009
I suspect that the following bit of code is causing problems - not
causing an arror - just stopping the macro part way through without an
error. Does anyone know any other ways of coding the follow, I suspect
it is the for Each loop causing the problems:

Any help appreciated
Jason

'====================================
For Each mySheet In myStorageBook.Worksheets

'check to see if the storage sheet is being used
'if it isn't then delete it
If mySheet.Range("C2") = "Empty" Then
Application.DisplayAlerts = False
mySheet.Delete
Application.DisplayAlerts = True
Else
If mySheet.Name <> "Input" And mySheet.Name <> "Summary"
Then
mySheet.Range("D:G").EntireColumn.AutoFit
End If
End If
Next
'====================================
 
Reply With Quote
 
 
 
 
Jacob Skaria
Guest
Posts: n/a
 
      17th Aug 2009
Is this a macro or a worksheet/workbook event ?


If this post helps click Yes
---------------
Jacob Skaria


"WhytheQ" wrote:

> I suspect that the following bit of code is causing problems - not
> causing an arror - just stopping the macro part way through without an
> error. Does anyone know any other ways of coding the follow, I suspect
> it is the for Each loop causing the problems:
>
> Any help appreciated
> Jason
>
> '====================================
> For Each mySheet In myStorageBook.Worksheets
>
> 'check to see if the storage sheet is being used
> 'if it isn't then delete it
> If mySheet.Range("C2") = "Empty" Then
> Application.DisplayAlerts = False
> mySheet.Delete
> Application.DisplayAlerts = True
> Else
> If mySheet.Name <> "Input" And mySheet.Name <> "Summary"
> Then
> mySheet.Range("D:G").EntireColumn.AutoFit
> End If
> End If
> Next
> '====================================
>

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      17th Aug 2009
I suspect this could be your problem
If mySheet.Range("C2") = "Empty" Then
Maybe assuming you have a set mystoragebook=something

For Each ws In myStorageBook.Worksheets
If ws.Name <> "Input" And ws.Name <> "Summary then
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
else ws.columns("D:G").AutoFit
end if



--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"WhytheQ" <(E-Mail Removed)> wrote in message
news:a2bf0778-6c01-4c0b-8648-(E-Mail Removed)...
>I suspect that the following bit of code is causing problems - not
> causing an arror - just stopping the macro part way through without an
> error. Does anyone know any other ways of coding the follow, I suspect
> it is the for Each loop causing the problems:
>
> Any help appreciated
> Jason
>
> '====================================
> For Each mySheet In myStorageBook.Worksheets
>
> 'check to see if the storage sheet is being used
> 'if it isn't then delete it
> If mySheet.Range("C2") = "Empty" Then
> Application.DisplayAlerts = False
> mySheet.Delete
> Application.DisplayAlerts = True
> Else
> If mySheet.Name <> "Input" And mySheet.Name <> "Summary"
> Then
> mySheet.Range("D:G").EntireColumn.AutoFit
> End If
> End If
> Next
> '====================================


 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      17th Aug 2009
I left out the most important part.....
If Len(Application.Trim(ActiveCell)) < 1 Then MsgBox "hi"
=========
For Each ws In myStorageBook.Worksheets
If ws.Name <> "Input" And ws.Name <> "Summary then
If Len(Application.Trim(ActiveCell)) < 1 Then
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
else ws.columns("D:G").AutoFit
end if
end if
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Don Guillett" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I suspect this could be your problem
> If mySheet.Range("C2") = "Empty" Then
> Maybe assuming you have a set mystoragebook=something
>
> For Each ws In myStorageBook.Worksheets
> If ws.Name <> "Input" And ws.Name <> "Summary then
> Application.DisplayAlerts = False
> ws.Delete
> Application.DisplayAlerts = True
> else ws.columns("D:G").AutoFit
> end if
>
>
>
> --
> Don Guillett
> Microsoft MVP Excel
> SalesAid Software
> (E-Mail Removed)
> "WhytheQ" <(E-Mail Removed)> wrote in message
> news:a2bf0778-6c01-4c0b-8648-(E-Mail Removed)...
>>I suspect that the following bit of code is causing problems - not
>> causing an arror - just stopping the macro part way through without an
>> error. Does anyone know any other ways of coding the follow, I suspect
>> it is the for Each loop causing the problems:
>>
>> Any help appreciated
>> Jason
>>
>> '====================================
>> For Each mySheet In myStorageBook.Worksheets
>>
>> 'check to see if the storage sheet is being used
>> 'if it isn't then delete it
>> If mySheet.Range("C2") = "Empty" Then
>> Application.DisplayAlerts = False
>> mySheet.Delete
>> Application.DisplayAlerts = True
>> Else
>> If mySheet.Name <> "Input" And mySheet.Name <> "Summary"
>> Then
>> mySheet.Range("D:G").EntireColumn.AutoFit
>> End If
>> End If
>> Next
>> '====================================

>


 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      17th Aug 2009
NOT a good day
If Len(Application.Trim(ws.range("c2"))) < 1 Then

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Don Guillett" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I left out the most important part.....
> If Len(Application.Trim(ActiveCell)) < 1 Then MsgBox "hi"
> =========
> For Each ws In myStorageBook.Worksheets
> If ws.Name <> "Input" And ws.Name <> "Summary then
> If Len(Application.Trim(ActiveCell)) < 1 Then
> Application.DisplayAlerts = False
> ws.Delete
> Application.DisplayAlerts = True
> else ws.columns("D:G").AutoFit
> end if
> end if
> --
> Don Guillett
> Microsoft MVP Excel
> SalesAid Software
> (E-Mail Removed)
> "Don Guillett" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>I suspect this could be your problem
>> If mySheet.Range("C2") = "Empty" Then
>> Maybe assuming you have a set mystoragebook=something
>>
>> For Each ws In myStorageBook.Worksheets
>> If ws.Name <> "Input" And ws.Name <> "Summary then
>> Application.DisplayAlerts = False
>> ws.Delete
>> Application.DisplayAlerts = True
>> else ws.columns("D:G").AutoFit
>> end if
>>
>>
>>
>> --
>> Don Guillett
>> Microsoft MVP Excel
>> SalesAid Software
>> (E-Mail Removed)
>> "WhytheQ" <(E-Mail Removed)> wrote in message
>> news:a2bf0778-6c01-4c0b-8648-(E-Mail Removed)...
>>>I suspect that the following bit of code is causing problems - not
>>> causing an arror - just stopping the macro part way through without an
>>> error. Does anyone know any other ways of coding the follow, I suspect
>>> it is the for Each loop causing the problems:
>>>
>>> Any help appreciated
>>> Jason
>>>
>>> '====================================
>>> For Each mySheet In myStorageBook.Worksheets
>>>
>>> 'check to see if the storage sheet is being used
>>> 'if it isn't then delete it
>>> If mySheet.Range("C2") = "Empty" Then
>>> Application.DisplayAlerts = False
>>> mySheet.Delete
>>> Application.DisplayAlerts = True
>>> Else
>>> If mySheet.Name <> "Input" And mySheet.Name <> "Summary"
>>> Then
>>> mySheet.Range("D:G").EntireColumn.AutoFit
>>> End If
>>> End If
>>> Next
>>> '====================================

>>

>


 
Reply With Quote
 
WhytheQ
Guest
Posts: n/a
 
      18th Aug 2009
On 17 Aug, 21:36, "Don Guillett" <dguille...@austin.rr.com> wrote:
> NOT a good day
> *If Len(Application.Trim(ws.range("c2"))) < 1 Then
>
> --
> Don Guillett
> Microsoft MVP Excel
> SalesAid Software
> dguille...@austin.rr.com"Don Guillett" <dguille...@austin.rr.com> wrote in message
>
> news:(E-Mail Removed)...
>
>
>
> >I left out the most important part.....
> > If Len(Application.Trim(ActiveCell)) < 1 Then MsgBox "hi"
> > =========
> > For Each ws In myStorageBook.Worksheets
> > *If ws.Name <> "Input" And ws.Name <> "Summary then
> > *If Len(Application.Trim(ActiveCell)) < 1 Then
> > * * Application.DisplayAlerts = False
> > * * * ws.Delete
> > * * Application.DisplayAlerts = True
> > else ws.columns("D:G").AutoFit
> > end if
> > end if
> > --
> > Don Guillett
> > Microsoft MVP Excel
> > SalesAid Software
> > dguille...@austin.rr.com
> > "Don Guillett" <dguille...@austin.rr.com> wrote in message
> >news:(E-Mail Removed)...
> >>I suspect this could be your problem
> >> If mySheet.Range("C2") = "Empty" Then
> >> Maybe assuming you have a set mystoragebook=something

>
> >> For Each ws In myStorageBook.Worksheets
> >> *If ws.Name <> "Input" And ws.Name <> "Summary then
> >> * * Application.DisplayAlerts = False
> >> * * * ws.Delete
> >> * * Application.DisplayAlerts = True
> >> else ws.columns("D:G").AutoFit
> >> end if

>
> >> --
> >> Don Guillett
> >> Microsoft MVP Excel
> >> SalesAid Software
> >> dguille...@austin.rr.com
> >> "WhytheQ" <whyt...@gmail.com> wrote in message
> >>news:a2bf0778-6c01-4c0b-8648-(E-Mail Removed)....
> >>>I suspect that the following bit of code is causing problems - not
> >>> causing an arror - just stopping the macro part way through without an
> >>> error. Does anyone know any other ways of coding the follow, I suspect
> >>> it is the for Each loop causing the problems:

>
> >>> Any help appreciated
> >>> Jason

>
> >>> '====================================
> >>> For Each mySheet In myStorageBook.Worksheets

>
> >>> * * * * * *'check to see if the storage sheet is being used
> >>> * * * * * *'if it isn't then delete it
> >>> * * *If mySheet.Range("C2") = "Empty" Then
> >>> * * * * * *Application.DisplayAlerts = False
> >>> * * * * * * * * *mySheet.Delete
> >>> * * * * * *Application.DisplayAlerts = True
> >>> * * *Else
> >>> * * * * * *If mySheet.Name <> "Input" And mySheet.Name <>"Summary"
> >>> Then
> >>> * * * * * * * * *mySheet.Range("D:G").EntireColumn.AutoFit
> >>> * * * * * *End If
> >>> * * *End If
> >>> Next
> >>> '====================================- Hide quoted text -

>
> - Show quoted text -



Hello Don
- thanks for all the help so far.

Bit of a misunderstanding (quite understandable) - in Range("C2") of
each of the sheets there is a formula using the IF function and one of
the options is the string "Empty" ....

=IF(ISNA(MATCH(B4,Input!C6:AZ6,0)),"Empty",MATCH(B4,Input!C6:AZ6,0))

Anyway I've moved the nested IFs around as you have and also changed
been more explicit with Range("C2") ... Range("C2").Value ; I know
this is the default property but maybe it'll help.

Will report back after testing

Thanks again
Jason.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help required with a simple Loop Pedros Microsoft Excel Programming 10 27th Jul 2006 12:57 PM
HELP required on XP Pro start-up loop please! =?Utf-8?B?U3RlZmFub19zcmdpeA==?= Windows XP Setup 1 20th Nov 2005 06:59 PM
For....Next loop code required uplink600 Microsoft Excel Programming 2 12th May 2004 04:03 PM
Alternative loop Arjen Microsoft C# .NET 2 2nd Feb 2004 04:55 PM
Alternative required for Birdging over WAN, without using WINS Mon Microsoft Windows 2000 Networking 1 11th Jan 2004 07:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:27 AM.