why doesn't this conditional wok?

Posted on 2013-01-07
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
  • 2
  • 2
  • 2
  • +2
LVL 45

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 29

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 45

Expert Comment

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

MyArray(2) = "Dog"
LVL 26

Accepted Solution

redmondb earned 500 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.

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

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

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
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 …

743 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

10 Experts available now in Live!

Get 1:1 Help Now