Reputation: 187
Quick Q:
Sub Ex()
Worksheets("ABC").Activate
If Range("B10").Text IsNot "USA" Then
Range("B11").Value = "Domestic"
Else
End If
End Sub
I am new to VBA, and have not picked up what I have done wrong here. I am trying to set up values in B11 such that if B10 is set to anything else other than "USA" then the value in must be "Domestic".
Bonus Question: Ideally I would like to be able to create a list in B11 if I select USA. How can I do this with data validation?
Upvotes: 0
Views: 1034
Reputation: 52008
IsNot
is a VB.Net rather than a VBA operator. Instead, use <>
(which corresponds to !=
in many other languages):
Sub Ex()
Dim ws As Worksheet
Set ws = Worksheets("ABC")
If ws.Range("B10").Text <> "USA" Then
ws.Range("B11").Value = "Domestic"
End If
End Sub
I made a couple of other changes: I introduced a worksheet variable and used it to qualify the Range()
(rather than relying on activation) and I dropped the spurious Else
.
Upvotes: 3