using if statement in excel VBA variable

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
Who is Participating?
Ingeborg Hawighorst (Microsoft MVP / EE MVE)Connect With a Mentor Microsoft MVP ExcelCommented:
if you want the variable ProjectTo to have the 99999 value, not the cell C17, then maybe

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

Open in new window

cheers, teylyn
Martin LissOlder than dirtCommented:
If ProjectTo = "" Then
    ActiveSheet.Range("C17").Value = "999999"
End If    

Open in new window

Saqib Husain, SyedConnect With a Mentor EngineerCommented:
Add this line below the existing projectto line

if ProjectTo ="" then ProjectTo =999999
Martin LissOlder than dirtCommented:
If that's not what you want then please explain further and/or show your coding attempt.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.