Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

using if statement in excel VBA variable

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

647 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