Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


why doesn't this conditional wok?

Posted on 2013-01-07
Medium Priority
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
If flg = True Then
   DirectCopyInfo = True
   'do nothing
   Sheets.Add.Name = MyArray(2)
   DirectCopyInfo = False
End If
Question by:javagair
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
LVL 49

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.
LVL 31

Expert Comment

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 !!!
LVL 49

Expert Comment

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

MyArray(2) = "Dog"
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

LVL 26

Accepted Solution

redmondb earned 2000 total points
ID: 38752641
Hi, javagair.

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

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" ...
LVL 31

Expert Comment

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 ??

Author Closing Comment

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

LVL 26

Expert Comment

ID: 38768231
Thanks, Gary.

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

688 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