?
Solved

using if statement in excel VBA variable

Posted on 2013-05-15
4
Medium Priority
?
565 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 49

Expert Comment

by:Martin Liss
ID: 39169868
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 1000 total points
ID: 39169869
Add this line below the existing projectto line

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

Expert Comment

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

Accepted Solution

by:
Ingeborg Hawighorst (Microsoft MVP / EE MVE) earned 1000 total points
ID: 39169878
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

752 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