User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » Visual basic and Excel question Page [1]  
moron
All American
34144 Posts
user info
edit post

I'm trying to use the Find() function in Visual Basic for an Excel macro, and I can't figure out how to detect whether the find was successful or not.

Set FoundCells = inventoryRange.Find(searchKey, LookIn:=xlValues, LookAt:=xlPart, MatchCase:=False)


The line of code and formant for the Find looks like that.

If it finds nothing, the FoundCells, according to the variable watcher, is the value of "Nothing" but I can't seem to figure out how to test for this in visual basic. I've tried FoundCells=null , FoundCells="" , FoundCells.value="" , FoundCells.value="nothing" . Visual Basic will throw an error if a value is nothing and you try to do anything with it, and I could exploit this, but it seems like they'd have a built-in way to test for null in this scenario. Does anyone happen to know of a way?

9/27/2007 2:30:52 AM

LimpyNuts
All American
16859 Posts
user info
edit post

If FoundCells Is Nothing Then
' empty results
' don't do shit
Else
' do shit
End If


There is a big difference between "Null" and "Nothing"

An Object type that has not been instanced is Nothing (i.e. FoundCells does not reference any object)

9/27/2007 2:42:49 AM

moron
All American
34144 Posts
user info
edit post

LimpyNuts, FTW!

I didn't realize that VB has a difference between = and "is". Thanks a lot man... that's been driving me crazy. I searched a ton of stuff online, and I guess I must have overlooked that distinction, since i'm not use to looking for it.

9/27/2007 12:28:49 PM

LimpyNuts
All American
16859 Posts
user info
edit post

9/27/2007 12:43:25 PM

 Message Boards » Tech Talk » Visual basic and Excel question Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.39 - our disclaimer.