I am able to do this:
but if I want to check a range of cells like so:![]()
If .Range("C5").Value = "AB1234" Then
I get a Type Mismatch Error. What is the correct syntax?![]()
If .Range("C5:C9".Value = "AB1234" Then
I am able to do this:
but if I want to check a range of cells like so:![]()
If .Range("C5").Value = "AB1234" Then
I get a Type Mismatch Error. What is the correct syntax?![]()
If .Range("C5:C9".Value = "AB1234" Then
You have to check each cell individually. You can however get the system to check a list of cells individually through a loop
![]()
for each rng in range("C5:C9") if rng.value = "AB1234" then 'Do something end if next
Ok that's a good idea but this is what I'm trying to do:
Is there a way to check for the value AB1234 in the range C5:C9 without having to check the other cells for each iteration?![]()
For Each Rng In Range("C5:C9") If Rng.Value = "AB1234" Then 'Do nothing End If next .Cells(5, 4).Value = "AC1234" And _ .Cells(6, 4).Value = "AD1234" And _ .Cells(7, 4).Value = "AE1234" And _ .Cells(8, 4).Value = "AF1234" Then
Cells are checked individually. You want have multiple criteria in your IF statement then you write them all.
If you want to make sure they are ALL true then just use another variable to track....:
![]()
dim all_ok as string all_ok = "yes" for each rng in range("C5:C9") if rng.value <> "AB1234" then all_ok = "no" end if next if all_ok = "yes" then do something
Please help by:
Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know
There are 10 kinds of people in this world... those who understand binary, and those who don't.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks