Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #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?
  #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.
  #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




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





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