Closed Thread
Results 1 to 4 of 4

Excel VBA Macros validations

Hybrid View

  1. #1
    Registered User
    Join Date
    09-24-2016
    Location
    Colombo
    MS-Off Ver
    Word
    Posts
    17

    Smile Excel VBA Macros validations

    Need a validations like below,

    e.g. V-b0982

    When user enters first character as alphabetic(except capital V) or numeric value or special character -- Validation message should be "First character should be V"
    When user enters second character as special character(except -) or numeric value or alphabetic -- Validation message should be "second character should be -"
    When user enters third character as special character or numeric value-- Validation message should be "third character should be alphabetic"
    When user enters last four characters as special character or alphabetic -- Validation message should be "last four characters should be numeric values"

  2. #2
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Excel VBA Macros validations

    Maybe :
    Private Sub Worksheet_Change(ByVal Target As Range)
      Dim rng As Range, strMsg As String
      Set rng = Intersect(Target, Range("C3:C" & Me.Rows.Count))  'Change "C3:C" as needed
      If Not rng Is Nothing Then
         If rng.Cells.Count = 1 Then
            If Len(rng.Value) = 7 Then
               If Mid$(rng.Value, 1, 1) <> "V" Then strMsg = strMsg & "First character should be V" & vbCrLf
               If Mid$(rng.Value, 2, 1) <> "-" Then strMsg = strMsg & "Second character should be -" & vbCrLf
               If Not Mid$(rng.Value, 3, 1) Like "[A-z]" Then strMsg = strMsg & "Third character should be alphabetic" & vbCrLf
               If Not Mid$(rng.Value, 4, 4) Like "####" Then strMsg = strMsg & "Last four characters should be numeric values" & vbCrLf
            Else
               If Len(rng.Value) <> 0 Then strMsg = "Incorrect length" & vbCrLf
            End If
            If Len(strMsg) Then MsgBox strMsg
         End If
      End If
    End Sub
    Attached Files Attached Files
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,913

    Re: Excel VBA Macros validations

    @ ThiliSuper

    Why not continue in your other thread so people can see other answers already given.

    http://www.excelforum.com/showthread...t=#post4487971
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,946

    Re: Excel VBA Macros validations

    Welcome to the Forum, unfortunately:

    This is a duplicate post and as such does not comply with Rule 5 of our forum rules. This thread will now be closed, you may continue in your other thread.

    Thread Closed.

    http://www.excelforum.com/showthread...t=#post4487971
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA Validations
    By uniquevisage in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-09-2013, 08:57 PM
  2. Excel 2007 : Need Support with Excel Validations
    By daredevilrocks in forum Excel General
    Replies: 3
    Last Post: 05-17-2011, 02:21 AM
  3. Two Validations
    By excelkeechak in forum Excel General
    Replies: 5
    Last Post: 08-26-2010, 02:45 PM
  4. Excel VBA script for Data Validations
    By singhabhijitkumar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-29-2010, 07:01 AM
  5. Validations Based On Previous Validations
    By PhatPhil in forum Excel General
    Replies: 5
    Last Post: 11-16-2009, 04:19 AM
  6. Two validations
    By Statsman in forum Excel General
    Replies: 5
    Last Post: 05-12-2009, 04:53 PM
  7. [SOLVED] How do I put in more than 7 validations in IF FORMALA in EXCEL
    By How do I put in more than 7 validations in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-26-2005, 08:05 AM
  8. problem: when paste => validations lost => excel corrupted !
    By stt_d31 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-04-2005, 01:29 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1