Multiple If Statement problem

G

GregR

I am cutting a PO an trying to save it based on the account or project
number. Here is part of the code:

Dim POFname as String
If Len(Range("F39").Value) = 12 Then
POFname = "PO " & Range("D6").Value & " for Store " &
Right(Range("F39").Value, 4) & ".xls"
'If Len(Range("F39").Value) = 18 Then
'POFname = "PO " & Range("D6").Value & " for Project " &
Left(Range("F39").Value, 6) & ".xls"
'If Len(Range("F39").Value) = 11 Then

POFname = "PO " & Range("D6").Value & " for Dept " &
Right(Range("F39").Value, 3) & ".xls"
'End If
'End If
End If

ActiveWorkbook.SaveAs FileName:=("C:\Documents and Settings\gregr\My
documents\POs\") & _
POFname

It all works as expected except if I uncomment the If statement that
relates to project. F39 value can be any of these formats:

xxx-xxx-xxx (Dept)
xxx-xxx-xxxx (Store)
xx-xxx-xxx-xxx-xxx (project)

The expect file name results should be:
PO xxxx for Dept xxx
PO xxxx for Project xx-xxx
PO xxxx for Store xxxx

TIA

Greg
 
G

Gary Keramidas

try this out

Sub test()

Dim POFname As String
If Len(Range("f39")) = 12 Then
POFname = "PO " & Range("D6").Value & " for Store " & _
Right(Range("f39").Value, 4) & ".xls"

ElseIf Len(Range("f39")) = 18 Then
POFname = "PO " & Range("D6").Value & " for Project " & _
Left(Range("f39").Value, 6) & ".xls"

ElseIf Len(Range("f9")) = 11 Then
POFname = "PO " & Range("D6").Value & " for Dept " & _
Right(Range("f39").Value, 3) & ".xls"

End If
Debug.Print POFname

End Sub
 
G

Gary Keramidas

try this out

Sub test()

Dim POFname As String
If Len(Range("f39")) = 12 Then
POFname = "PO " & Range("D6").Value & " for Store " & _
Right(Range("f39").Value, 4) & ".xls"

ElseIf Len(Range("f39")) = 18 Then
POFname = "PO " & Range("D6").Value & " for Project " & _
Left(Range("f39").Value, 6) & ".xls"

ElseIf Len(Range("f9")) = 11 Then
POFname = "PO " & Range("D6").Value & " for Dept " & _
Right(Range("f39").Value, 3) & ".xls"

End If
Debug.Print POFname

End Sub
 
T

Tom Ogilvy

Dim POFname as String
If Len(Range("F39").Value) = 12 Then
POFname = "PO " & Range("D6").Value & " for Store " & _
Right(Range("F39").Value, 4) & ".xls"
Elseif Len(Range("F39").Value) = 18 Then
POFname = "PO " & Range("D6").Value & " for Project " & _
Left(Range("F39").Value, 6) & ".xls"
Elseif Len(Range("F39").Value) = 11 Then
POFname = "PO " & Range("D6").Value & " for Dept " & _
Right(Range("F39").Value, 3) & ".xls"
End If
 

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