?
Solved

using if statement in excel VBA variable

Posted on 2013-05-15
4
Medium Priority
?
569 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 50

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 50

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

839 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