Easy VBA syntax

normpam

Active Member
Joined
Oct 30, 2002
Messages
360
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

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
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

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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