Solved

test string from textbox for alpha or numeric characters

Posted on 2014-10-07
8
131 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 45

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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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 45

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now