Solved

using if statement in excel VBA variable

Posted on 2013-05-15
4
549 Views
Last Modified: 2013-05-15
Hi Experts,

I have reached the bounds of my limited capability and could do with some assistance with my excel VBA

I am wanting to assess a variable 'ProjectTo' with an if statement.

Current State

My VBA currently takes values from specified cells in an active sheet and subsequently passes these to an SQL string, which is all working fine.


Dim ProjectTo As String
Dim ProjecTFrom As String


ProjectFrom = ActiveSheet.Range("C16").Value
ProjectTo = ActiveSheet.Range("C17").Value

Desired State

For the 'ProjectTo' I would like to use an IF statement, along the line of "if the cell contents 'C17' is empty then use a hardcoded value of say '999999' else use the cells contents"

I have tried inserting IF statements into the above (current state) however receive error messages that I am unable to get past and therefore need some expert assistance please.

Many thanks
0
Comment
Question by:RSTOCKEWLL
  • 2
4 Comments
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
If ProjectTo = "" Then
    ActiveSheet.Range("C17").Value = "999999"
End If    

Open in new window

0
 
LVL 43

Assisted Solution

by:Saqib Husain, Syed
Saqib Husain, Syed earned 250 total points
Comment Utility
Add this line below the existing projectto line

if ProjectTo ="" then ProjectTo =999999
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
If that's not what you want then please explain further and/or show your coding attempt.
0
 
LVL 50

Accepted Solution

by:
teylyn earned 250 total points
Comment Utility
if you want the variable ProjectTo to have the 99999 value, not the cell C17, then maybe

If  ActiveSheet.Range("C17") = "" Then
    ProjectTo = "999999"
Else
   ProjectTo =  ActiveSheet.Range("C17")
End If    

Open in new window


cheers, teylyn
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

771 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

8 Experts available now in Live!

Get 1:1 Help Now