Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 90219

How to do if "=" multiple values"

$
0
0

So I am relatively new to vba but am trying. I want a message to show if a user attempts to change a cell based on its column title. Before anyone comments that I can just protect the cells I am aware of this but it would be useful for future knowledge anyway. Rather than having multiple if statements I want to something similar to the where in() that is in SQL. It would be also useful if you could suggest a way of doing not in or would you just use an else? The code I currently have that works for one value is below

Dim ThisColumn as long
ThisColumn=Target.Column
        If Cells(1, ThisColumn).Value = "# workers" Then
                Application.EnableEvents = False
                Application.Undo
                Application.EnableEvents = True
                MsgBox "Protected Columns"
            Exit Sub

End If

But I want something like

If Cells(1, ThisColumn).Value in("# workers","# of people") Then
        Application.EnableEvents = False
        Application.Undo
        Application.EnableEvents = True
        MsgBox "Protected Columns"
    Exit Sub
    End If

Thanks for any help!


Viewing all articles
Browse latest Browse all 90219

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>