Question Locked

VBA Program

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I am doing a program in VBA and running it in Microsoft excel.

For example,
when typing the input, the user is supposed to type "234-L1-23-23". Instead, if the user typed "234 - L1 - 23 - 23"(The error is the spacing) the whole program hangs.

my question is this, is there any way of programming in VBA can solve this error?? or Is this error can be avoided if the C++ program were used instead of VBA.

5 replies

by stevehab

Not sure where the result is being used, but let me take a guess that the data is a string variable and that you are placing this user data in a cell. If so, does the target cell appear to be treating as text? If so, append an "=" in front before placing. If not that, then maybe use, I think (I'm have Open Office on this pc, but usually use Excel 2003/Access/SQL/MDX), a function like REPLACE or FIND to remove the spaces since that seems to work.

If you have specific VBA lines to show how this is used and any defined data types, that would be hepful.

Good luck!

by chaos.theory

Only just seen this question, but in case it's still relevant,
the answer is Yes. VBA can easily be made to check the
string structure and identify non allowable entries.

A trivial way would be to detect any spaces, however I
guess there may be some sort of logic or rule for the four
elements to this string. In which case the error checking
could be extended to cover the validity of the elements to
the string.

If you need further help or advice just post back.

Regards

by camerondruyor

You have probably already discovered this, but here it is anyway:

You can use VBA's replace function to get rid of all spaces in the string.

user_input = Replace(user_input, " ", "")

This discussion is closed to new replies.