Testing for text using VBA

R

RJQMAN

I have been experimenting trying to find a way to use VBA to test to
see if a user has entered text into a cell.

I have tried Len and istext without success - perhaps I am not doing
it correctly, I am not sure. However through trial and error I found
something that seems to work - I just want to be sure that it is not a
fluke (no insult to the Fluke Mfg. company intended).

I am trying in this example to determine if there is text in cell
E14. I found that if I compare the value cell E14 to a positive
integer (and then place a numerical value in cell G14 just as a test),
it seems to work as follows;

If Range("E14").Value < 1 Then Range("G14").Value = 7

I find that if cell E14 has text in it, then the formula runs and G7
remains blank. If there is text in E14, then the formula result is
that G7 returns the value of 7. I have tried this with several
entries, and it seems to work. The cell E14 is set to 'General' by
the way.

I do not understand why it works. Is this going to work all of the
time, or is it just a fluke? I would appreciate knowing if I am
creating a problem for myself in the future if I use this test in a
VBA program. Can someone tell me if what I am doing is going to be
reliable and work in the future?

Thanks in advance, again...
 
R

RJQMAN

"If you can hear this, it must be a fluke" LOL

Try testing your logic with input like 123abc.

I think a better way would be
   If Not IsNumeric(Range("E14").Value) Then
     ' is (or contains) text- Hide quoted text -

- Show quoted text -

Thanks for your reply. I did test it as you suggest, and it still
seemed to work fine. The user will be entering the names of high
schools, and they will always start with text, by the way. The
program calculates scores of a high school interscholastic band
competition, and I want the program to see if there is a school name
entered into the cell. The names are things like "Citrus High
School." They will never be numeric, as far as I can envision, but I
tried the logic with the quasi-numeric entry, and with entries that
have a space in the first character, and it still seems to work.

I am such a novice that I do not understand the logic you have
suggested - I am self taught, and I know more every minute I work,
but I have barely scratched the surface. I want to take a class from
someone who really knows what they are doing one of these days. Whew.

It is great to have someone else look at this for me, and I cannot
tell you how much I appreciate your taking the time and effort to
respond. Hmm. I think I hear something... must be that fluke,falling
in the forest. I wonder if every fluke is really a diferent shape?
Or was that flakes? Hmm. LOL.

Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top