Solved

why doesn't this conditional wok?

Posted on 2013-01-07
8
178 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
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 46

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 29

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 46

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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 142

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 29

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now