If statement to set two variables

wmtsub

Active Member
Joined
Jun 20, 2018
Messages
322
Is it possible to:

If [condition] then a="1',and aa="25"

Can not seem to figure the context out.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
If you are using VBA try:
Code:
If [condition] then 
     a="1"
     aa="25"
End If
If you want those variables to be numbers, remove the quote marks.
 
Upvote 0
I keep gettin errors
"End if without block if"



If awsn = "FINANCE" Then
mg = "Onboard Finance"
m = "Finance"
ActiveSheet.Unprotect "FINANCE"
End If

If awsn = "MERCURY" Then
mg = "Onboard Mercury"
m = "Mercury"
ActiveSheet.Unprotect "MERCURY"
End If

If awsn = "EMAIL" Then mg = "Onboard Complete"
m = "Complete"
ActiveSheet.Unprotect "EMAIL"
End If
 
Upvote 0
The issue is with your last block:
Code:
[COLOR=#333333]If awsn = "EMAIL" Then mg = "Onboard Complete"[/COLOR]
[COLOR=#333333]m = "Complete"[/COLOR]
[COLOR=#333333]ActiveSheet.Unprotect "EMAIL"[/COLOR]
[COLOR=#333333]End If[/COLOR]

There are two ways to write IF ... THEN statements in VBA.
One, is to have the whole thing on one line.
In that instance, you would have something on the same line after the word THEN.
However, if you use this option, everything has to be on one line, so you don't have an "END IF" line.

The second is to have it on multiple lines, like the first two you did.
In that case, you need to have an END IF line.

So correct your last block like this:
Code:
[COLOR=#333333]If awsn = "EMAIL" Then 
mg = "Onboard Complete"[/COLOR]
[COLOR=#333333]m = "Complete"[/COLOR]
[COLOR=#333333]ActiveSheet.Unprotect "EMAIL"[/COLOR]
[COLOR=#333333]End If[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,259
Members
452,626
Latest member
huntinghunter

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