My Plus Sign Keeps Disappearing

Ed Song

Board Regular
Joined
Sep 1, 2014
Messages
90
I'm trying to add two variables together, but my plus sign keeps disappearing. My program looks like this:

Dim Unlim_H_Grp2 As Double
Dim SatH As Double
Dim IH_Grp2 As Double
Dim SatH As Double
Dim IH_Grp2 As Double
Dim DepRateH As Double
Dim Init_H_Grp2 As Double


If Unlim_H_Grp2 >= SatH Then
IH_Grp2 H_Subs_Grp2 = SatH - (1 - DepRateH) * Init_H_Grp2
H_Grp2 = SatH
Else
IH_Grp2 = IH_Grp2
H_Grp2 = Unlim_H_Grp2
End If

I want the second row, the first row underneath the If statement to read:

IH_Grp2 + H_Subs_Grp2 = SatH - (1 - DepRateH) * Init_H_Grp2

However, every time I insert the plus sign it disappears. If I run the program, I get an error "Expected, Sub, Function, or Property" message.

Any suggestions? Is my file corrupted? If so, what can I do to fix the problem?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
You can only declare the value of one variable at a time. Trying to do "a+b = c - d" will always give an error. You need to tell excel what the value of IH_Grp2 and H_Subs_Grp2 are separately.
 
Upvote 0
I'm trying to add two variables together, but my plus sign keeps disappearing. My program looks like this:

I want the second row, the first row underneath the If statement to read:

IH_Grp2 + H_Subs_Grp2 = SatH - (1 - DepRateH) * Init_H_Grp2

However, every time I insert the plus sign it disappears. If I run the program, I get an error "Expected, Sub, Function, or Property" message.
You cannot have an expression (something that needs to be evaluated) on the left side of an equal sign that is used for an assignment. What did think the above line of code would do (explain in detail so we can figure out what code line you should be using)? Just so you know, the first equal sign in a code line is not an equal sign like in a algebraic formula... it is strictly and assignment operator... it evaluates what is on the right and assigns it to what is on the left and what is on the left needs to be a variable, array element, object property, and so on, all of which are single "things".
 
Upvote 0
Thanks for your reply. However, my program is very long so only a small portion of the program is being presented. IH_Grp2 and H_Sub_Grp2 were set to values earlier in the program. Furthermore, yesterday it was working, and today, without any changes its not.
 
Upvote 0
IH_Grp2 and H_Sub_Grp2 were set to values earlier in the program. Furthermore, yesterday it was working, and today, without any changes its not.
This line of code (with the plus sign)...

IH_Grp2 + H_Subs_Grp2 = SatH - (1 - DepRateH) * Init_H_Grp2

could never have worked... VB would never allow it to stand like that.
 
Upvote 0
I have four other versions of the program with the same line that works. Apparently, VB does allow it to stand like that. But anyway, from now on, I'll only have one variable on the left side of the equation. Thanks for the tip.
 
Upvote 0
It's really weird. A+B = C+D seems to work about 80 percent of the time in my version of VBA Excel, and fails about 20 percent of the time. Nevertheless, now I know that putting two variables on the left side of the equation is unstable in VBA.
 
Upvote 0
I have four other versions of the program with the same line that works. Apparently, VB does allow it to stand like that. But anyway, from now on, I'll only have one variable on the left side of the equation. Thanks for the tip.
You say you have this, with the + sign...

IH_Grp2 + H_Subs_Grp2 = SatH - (1 - DepRateH) * Init_H_Grp2

sitting on a line by itself (that is, not as part of an If..Then statement or as the argument to a function call, but rather just as posted above, on a line all by itself)? Sorry, I do not believe you... I have been programming in various forms of BASIC (the compiled version of VB's predecessor), the compiled version of VB (VBA's predecessor) since 1981 and I can assure you that none of them ever permitted a stand-alone expression to exist on the left side of an equal sign for in an assignment statement. I am curious, though, if that line of code were to be able to work, what do you think would get assigned to what?
 
Upvote 0
It's really weird. A+B = C+D seems to work about 80 percent of the time in my version of VBA Excel, and fails about 20 percent of the time. Nevertheless, now I know that putting two variables on the left side of the equation is unstable in VBA.
What version of Excel are you using?

Would you do me a favor and send a file, and tell me the values you have for variables A, B, C and D, when it works? My email address is...

rick DOT news AT verizon DOT net
 
Upvote 0
It's really weird. A+B = C+D seems to work about 80 percent of the time in my version of <acronym title="visual basic for applications" style="border-width: 0px 0px 1px; border-bottom-style: dotted; border-bottom-color: rgb(0, 0, 0); cursor: help; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">VBA</acronym> Excel, and fails about 20 percent of the time. Nevertheless, now I know that putting two variables on the left side of the equation is unstable in <acronym title="visual basic for applications" style="border-width: 0px 0px 1px; border-bottom-style: dotted; border-bottom-color: rgb(0, 0, 0); cursor: help; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">VBA</acronym>.

I have to agree with Rick on this. There is no instance where the above would ever work. VBA would stop it, as would any other compiler in any language. I am interested in how that was executed.
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top