Easy VBA syntax

normpam

Active Member
Joined
Oct 30, 2002
Messages
355
If Cell.Value = "I&S" Then Cell.Offset(0, 1).Value = "No" And Cell.Offset(0, 2).Value = "Yes"

The first part of the above code works fine - if the cell being evaluated is "I&S" then the cell to the right populates with "No". This works because I ran it separately. But when I add the second part

And Cell.Offset(0, 2).Value = "Yes"

I get an error message.

What am i missing here?

Thanks!
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try
Code:
If Cell.Value = "I&S" Then 
    Cell.Offset(0, 1).Value = "No" 
    Cell.Offset(0, 2).Value = "Yes"
end if
 
Upvote 0
Alternatively
Code:
If cell.Value = "I&S" Then cell.Offset(0, 1).Resize(, 2).Value = Array("No", "Yes")
 
Upvote 0
Thanks. Works. Is it possible to get both conditions on one line without using a Block If?
I've got about another seven conditions to do the same thing, and would be great to get them on one line each, so to speak. I know that the And operator can be used on one line; I've used it successfully before with multiple conditions.
 
Upvote 0
Did you see my suggestion?
 
Upvote 0

Forum statistics

Threads
1,215,453
Messages
6,124,918
Members
449,195
Latest member
Stevenciu

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