Nested If statements

R

Robert Christie

Hi
I'm trying to name a .TXT file opened in excel, if cell A2 contains within
it's value the words "List........".
I was able to name the first "Output1" but on running the code on the
another file error 1004 appeared saying I cannot name the file with the same
name.
Could you explain the error in my code?
Or a different method.

If Range("A2").Value <> "List with Date of Birth" Then
ActiveSheet.Name = "Output1"
Else
If Range("A2").Value <> "List of School Card" Then
ActiveSheet.Name = "Output2"
Else
If Range("A2").Value <> "List of ATSI Students with " Then
ActiveSheet.Name = "Output3"
End If
End If
End If

TIA
--
Thank you

Regards

Bob C
Using Windows XP Home + Office 2003 Pro
 
O

Otto Moehrbach

Robert
The parameter "<>" means "doesn't equal". The way you wrote your
arguments in the 3 "If" statements, each is true if A2 is "Doodle". In
fact, each of the 3 are True if A2 is anything other than what that "If"
statement uses. I can't offer a correction because I don't know what you
want to do with those "If" statements. Please post back with the logic you
want to use. HTH Otto
 
R

Robert Christie

Hi Otto

Thank you for your reply.
The parameter I require is If A2 contains the string "List with date...."
then name that sheet "Output1".
I'm opening three .TXT files which do not indicate in their names what
particular student information data they hold, but the A2 cell does. So I
would like to check part of A2 content and name the each sheet in order they
order of use. The .TXT files are reports generatered from another computer
system and are not allways produced in the same order.
HTH you understand my requirments.

Regards Bob C
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top