Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 18th, 2003, 08:54 AM
Registered User
 
Join Date: Sep 2003
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Search for Character in String

I want to be able to detect a character in a string.

For instance...if the user types in "AD45BS", I want to check if the 3rd character in that string is a "4".

How can I do that with a VB form in Excel?
Reply With Quote
  #2 (permalink)  
Old September 18th, 2003, 09:34 AM
Registered User
 
Join Date: Sep 2003
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I figured it out.

Dim z
z = Mid(myString, 3, 1)

The search starts at the 3rd character and moves 1 to the right therefore selecting the 3rd character.
Reply With Quote
  #3 (permalink)  
Old April 24th, 2004, 11:13 AM
Registered User
 
Join Date: Apr 2004
Location: Smithtown, NY, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Mike D
Default


 You can also create a loop to check for valid characters,
 Here is part of a code that works after the DIM initialize:

  ' Check for length = 12, and proper hex characters
    Do
        charlength = Len(CStr(Range("C" & (i + 5))))
        If (charlength = 12) Then
              j = 1: i = 1: x = 1
             CharString = (CStr(Range("C" & (i + 5))))
            Do
                Select Case UCase(Mid$(CharString, j, 1))
                    Case Is = "0", "1", "2", "3", "4", "5", "6", "7", _
                              "8", "9", "A", "B", "C", "D", "E", "F"
                    Case Else
                        Range("C" & (i + 5)).Select
                        MsgBox "Illegal Character ( Not HEX character ) in string " _
                        & Range("C" & (i + 5)) & Chr(10) & Chr(13) & _
                        "Character=" & UCase(Mid$(CharString, j, 1)) & " j=" & j
                        Flag1Error = True: Skip = True
                End Select
                j = j + 1
            Loop Until (j > 12) Or (Flag1Error = True)
            If (Flag1Error = False) Then
                Range("F" & (i + 5)) = "OK"
            End If
        Else
            MsgBox "Not 12 characters long " & Range("C" & (i + 5))
            Flag1Error = True
        End If
        i = i + 1: j = 1
    Loop Until (i > 25) Or (Flag1Error = True) Or (Range("C" & (i + 5)) = "")
    If (Flag1Error = True) And (Skip = False) Then
        Msg = "Error in Data - Call ClearData_FG"
        Call SendMessage(Msg, Title)
    End If


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
New text search doesn't preselect search string planoie Visual Studio 2005 0 July 23rd, 2007 06:47 AM
trim a string to the first character jd_erd Access 2 May 6th, 2007 11:01 PM
string character conversion Neal XSLT 2 February 23rd, 2006 08:23 AM
Cutting a character from a string arnabghosh Classic ASP Basics 2 August 18th, 2005 07:44 AM
Replacing a character from string itHighway Classic ASP Basics 5 March 14th, 2005 11:15 PM



All times are GMT -4. The time now is 05:16 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.