0

I have this code

Sub ifcitythencity()

If InStr(1, (range("A2").Value), "San Francisco") > 0 Then range.Value("B2") = "San Francisco"

End Sub

But when I run the debugger, I get the error "Compile error: Argument not optional," and it highlights the second "range." What's causing this error?

2
  • 1
    Try range("B2").Value = "San fran" Aug 4, 2015 at 16:16
  • 4
    I'm voting to close this question because it describes a problem that went away when a typo was fixed as it is unlikely to help future readers, and because, being about programming, it's off-topic. Aug 4, 2015 at 19:38

1 Answer 1

3

You were using range.value("B2") rather than range("B2").value -

Sub ifcitythencity()

If InStr(1, (range("A2").Value), "San Francisco") > 0 Then range("B2").Value = "San Francisco"

End Sub

The error

argument not optional

gives you the clue as to the problem - the range(arg) object has to have an argument within the ().

Not the answer you're looking for? Browse other questions tagged .