Solved

test string from textbox for alpha or numeric characters

Posted on 2014-10-07
8
137 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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 26

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
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.

808 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