Solved

why doesn't this conditional wok?

Posted on 2013-01-07
8
185 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

776 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