Dim xxx As String & IF?

  • Thread starter RayportingMonkey
  • Start date
R

RayportingMonkey

I am using CDO Mail to distribute reports. My script has been wroking great
and sends out multiple reports, however I now have to setup more that one
distribution list...

I already have logic that identifies what reports are being sent and want to
use something similar to choose the distro list, but I don't know if using an
IF statement is valid when defining a variable.

Here's a snippet of the code I am trying to use:

Dim SCType As String
SCType = sh.Range("K6")

Dim Distro As String
If SCType = "WFSCScheduler" Then
Distro = "(e-mail address removed)"
Else: Distro = "(e-mail address removed)"
End
End If

Yeah, I suppose I could put a formula in the sheet and define the distro
that way, but I really hate to clutter up my sheets... Also, I may need to
build additional distros, so additional Else/IF Statements may be necessary.

What am I doing wrong?

Thanks!
Ray
 
G

George Nicholson

1) Take out the 'End' statement. That stops all code & resets all variables.
Do that and what you have will probably work fine.

2) If you expect you will be adding additional conditions, consider using a
Select Case structure rather than a If..Then..ElseIf: Unless you have a
simple either/or condition, I find it much easier to read, debug & maintain.

Select Case SCType
Case "WFSCScheduler"
Distro = "(e-mail address removed)"
Case "SomeNewValue", "NewWFSC"
Distro = "(e-mail address removed)"
Case Else
Distro = "(e-mail address removed)"
End Select


HTH,
 

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