Solved

test string from textbox for alpha or numeric characters

Posted on 2014-10-07
8
135 Views
Last Modified: 2014-10-08
vba 2010

userform textbox37

what i need:

I have a variable assigned to a userform textbox
cD =  Userform2.Textbox37.text

The textbox is being filled from an  activecell.value  on the sheet

I need to check  cD to test whether or not it contains alpha or numeric characters..

I'm picking up what appears to be  " "  FROM THE Sheet cell, but cant capture what it is...so trying to determine what it is NOT ?

I have tried   ISEMPTY
VBNULLSTRING

IF cD  = " "

none of these work ?

thanks
fordraiders
0
Comment
Question by:fordraiders
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 40367158
Try
 Userform2.Textbox37.Value

instead of .Text
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40367159
Can you attach your workbook and describe the process you want to check?
0
 
LVL 3

Author Comment

by:fordraiders
ID: 40367175
If IsEmpty(UserForm2.TextBox37.value) = True Then
MsgBox "No Item To Srearch On", vbCritical, "Null Search"
End If

no good
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 40367179
If Format(UserForm2.TextBox37.value) = vbNullString Then
MsgBox "No Item To Srearch On", vbCritical, "Null Search"
End If
0
 
LVL 25

Accepted Solution

by:
ProfessorJimJam earned 167 total points
ID: 40367181
here you go

create a userform and then add a text box and then click on view code of the userform and then paste this.   it will work. I tested it

Private Sub UserForm_Initialize()
    Dim ctl As Control
  Dim LC As Integer ' Loop counter
  Dim testText As String

    For Each ctl In Me.Controls
        If TypeName(ctl) = "TextBox" Then
         
   
   If Len(Me.TextBox1.Text) = 0 Then
     MsgBox "Box is empty"
     Exit Sub
   End If
   testText = Me.TextBox1.Text
   For LC = 1 To Len(testText)
     If Not IsNumeric(Mid(testText, LC, 1)) Then
       MsgBox "Entry is not entirely numeric."
       Exit Sub
     End If
   Next
   MsgBox "Entry is numeric."
        End If
    Next ctl
End Sub

Open in new window

0
 
LVL 46

Assisted Solution

by:Martin Liss
Martin Liss earned 167 total points
ID: 40367182
Try
If Trim(UserForm2.TextBox37.value) = "" Then
MsgBox "No Item To Srearch On", vbCritical, "Null Search"
End If

Open in new window

0
 
LVL 40

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 166 total points
ID: 40367190
Trim is the way to go:

From here:  http://microsoft.wikia.com/wiki/Microsoft_Office/VBA/General

this is a generic one
Function IsNullOrEmpty(val As Variant) As Boolean
   'First conditional validates for Nothing
   'Second condition validates for an Empty String situation "" or "     "
   Dim ret As Boolean: ret = False
   If IsMissing(val) Then
      ret = True
   ElseIf (val Is Nothing) Then
      ret = True
   ElseIf (val & vbNullString = vbNullString) Then
      ret = True
   ElseIf (Len(Trim(val)) <= 0) Then
      ret = True
   End If
 
   IsNullOrEmpty = ret
End Function

Open in new window


Usage:
if IsNullOrEmpty(UserForm2.TextBox37.value) then
MsgBox "No Item To Srearch On", vbCritical, "Null Search"
End If
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 40368423
i finally found a solution also...works fine..
http://www.techonthenet.com/excel/formulas/alphanumeric.php
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question