Solved

why doesn't this conditional wok?

Posted on 2013-01-07
8
207 Views
Last Modified: 2013-01-11
sheet names are sheettest,save,sheettest2.
MyArray(2) is Dog
set two watches to make sure that is what is being seen.
fig is set to false
fig becomes true even though it never finds a sheet called Dog.
can someone see why????????

For Each WS In Worksheets
If WS.Name Like MyArray(2) Then flg = True: Exit For
Next
If flg = True Then
   DirectCopyInfo = True
   'do nothing
Else
   Sheets.Add.Name = MyArray(2)
   DirectCopyInfo = False
End If
0
Comment
Question by:javagair
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 48

Expert Comment

by:Martin Liss
ID: 38752599
What are all your worksheet names? And why do you use 'Like' rather than '='?

This article of mine may help you. It's aimed at VB6 but most of it allies to VBA.
0
 
LVL 31

Expert Comment

by:gowflow
ID: 38752623
what do you meant by:
MyArray(2) is Dog

how does it translate in VBA ??? all the rest is fine. The only hick-up is
MyArray(2) is Dog
This is un heared of for me so far !!!
gowflow
0
 
LVL 48

Expert Comment

by:Martin Liss
ID: 38752631
What the Author means is that somewhere in the code he has something like

MyArray(2) = "Dog"
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 26

Accepted Solution

by:
redmondb earned 500 total points
ID: 38752641
Hi, javagair.

Please add the following line...
Debug.Print myarray(2) & " - " & ws.Name & " - " & flg
...after....
For Each ws In Worksheets
... and let us know what's output to the Immediate Pane.

Thanks,
Brian.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38752645
you write "fig" but in the code you write "flg"
please make sure it's not a plain "typo" ...
0
 
LVL 31

Expert Comment

by:gowflow
ID: 38752672
I don't see hjow your Flg goes to True
check out this file make sure macroes are set to enabled

noted also as angelIII pointed out the fig and flg maybe a typo in your code setting already fig to True whyle ur looking for flg ??
gowflow
test.xls
0
 

Author Closing Comment

by:javagair
ID: 38768215
copy don't type is the rule
l and i are not interchangeable except to us blind guys

gary
0
 
LVL 26

Expert Comment

by:redmondb
ID: 38768231
Thanks, Gary.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a serious pitfall that can happen when deleting shapes using VBA.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question