I have search high and low, but I am after a vba code to search a range, ie A1:A1000, and if it finds a cell that contains a space, then to pop up with a message box.
Thanks
I have search high and low, but I am after a vba code to search a range, ie A1:A1000, and if it finds a cell that contains a space, then to pop up with a message box.
Thanks
How about..
Set r = Range("A1:A1000").Find(What:=" ", LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False)
If r Is Nothing Then
' code to run if nothing found
Else
MsgBox "Space found in cell " & r.Address
End If
EDIT - removed the After:
parameter as this caused issues when cell beyond search area was active.
Just an example:
Dim cell As Range
Set cell = Range("A1:A1000").Find(What:=" ", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If cell Is Nothing Then
Stop 'do something
Else
Stop 'do something else
End If
More info: https://msdn.microsoft.com/en-us/library/office/ff839746.aspx