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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
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,215,398
Messages
6,124,699
Members
449,180
Latest member
craigus51286

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