Question:
Excel: VBA: Check if all cells equal "test"?
djdx2
2009-05-18 20:29:02 UTC
Ok, it might be VERY simple or not possible at all...

im trying to check if a "Range of Cells" equal the same thing (which is "Test")


Code =

Sub testing()

If Range("A1:A4").Value = "test" Then
Range("C6").Value = "all cells equal test"
Else
Range("C6").Value = "not all cells equal test"
End If

End Sub



but it comes up with an error......
im guessing you cant check the cells this way....

any help?
Five answers:
anonymous
2009-05-18 20:45:06 UTC
You have to check the cells individually.



Sub testing()

Dim I As Integer

Dim ok As Boolean

ok = True

For I = 1 To 4

If Range("A" & I).Value <> "test" Then

ok = False

Exit For

End If

Next



If ok Then

Range("C6").Value = "all cells equal test"

Else

Range("C6").Value = "not all cells equal test"

End If

End Sub
anonymous
2017-01-22 01:03:46 UTC
1
?
2016-10-04 05:53:07 UTC
Vba Not Equal
Simon Belmont
2009-05-22 08:18:08 UTC
This code check any selection not only a1:a4 and check if any value is equal to test. If it finds a value not equal to test, shows a message box say that and close code.



Sub testing()

dim xcel as cells



for each xcell in selection.cells

if xcell.value <> "test" then

msgbox "Not all cells are equal to test",vbinformation

exit sub

end if

next xcell

msgbox "All selected cells are equal to test",vbinformation

end if
anonymous
2016-10-26 01:12:37 UTC
perfect answer to Blackened. i'd only upload that usually circumstances, one does no longer understand how the person entered the most be conscious: examine, examine, examine, examine, etc. I consistently use the following solution to take the 'case' ingredient out of the blend: sub clearCheck() dim c as determination for each c in determination("G9:G500") if uCase(c.value) = "examine" Then ' converts 'c.value' to uppercase previous to evaluation. c.Entirerow.ClearContents end If next end Sub


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...