Pagina precedente | 1 | Pagina successiva
Vota | Stampa | Notifica email    
Autore

controllo formato casella di testo

Ultimo Aggiornamento: 09/05/2022 13:52
Post: 1
Registrato il: 14/07/2018
Città: MILANO
Età: 57
Utente Junior
excell 2010
OFFLINE
08/05/2022 23:17

Salve a tutti,
è la prima volta che partecipo a queste discussioni e da poco sto famigliarizzando con il linguaggio VBA,🙈 per programmare uno schedario.
Per caso, potete indicarmi una piccola tool per controllare il formato della casella di testo, modo che all'inserimento, risulti contenente il simbolo "*@*.*".
Grazie
Post: 115
Registrato il: 27/12/2016
Città: SIENA
Età: 50
Utente Junior
Office 2019/Office 365
OFFLINE
09/05/2022 09:04

Ciao,
non vedo la necessità di utilizzare VBA per una cosa del genere a meno che tu non voglia implementare il codice per altre ragioni. Per un semplice controllo dovresti andare sul tab dati-->convalida dati--> personalizzato e inserire la formula =VAL.NUMERO(CONFRONTA("*@*.?*";A1;0)) (è quella che utilizzo io per controllare gli indirizzi email).
Da verificare se il separatore è ; o ,

con VBA puoi trovare diverse soluzioni (questa è uno dei risultati)
email
Function emailTest(eAddr As String) As Boolean
    
    Dim myStr As String
    Dim MyChar As String
    Dim i As Long
    Dim n As Long
    Dim myArr
    
    emailTest = False
    
'test for 1 and only 1 "@" character, and no double 'dots'.
    If InStr(1, eAddr, "..") > 0 Then Exit Function
    myArr = Split(eAddr, "@")
    If UBound(myArr) <> 1 Then Exit Function
    
'tests for local segment of address (left of @)
    myStr = myArr(0)
    'Local name segment can be entirely in quotes (chr34) with any characters in between.
    If Left(myStr, 1) = Chr(34) And Right(myStr, 1) = Chr(34) _
     And Len(myStr) > 3 Then
        'skip next step - evaluation by character
    Else
        For i = 1 To Len(myStr)
            MyChar = Mid(myStr, i, 1)
            Select Case MyChar
                Case "0" To "9", "a" To "z", "A" To "Z"
                    'allow, and continue to next char
                Case "-", "!", "#", "$", "%", "'", "*", _
                     "+", "=", "?", "^", "`", "{", "}", _
                     "|", "~", ".", "_"
                    'these characters are not allowed at begin or end of local name
                    If i = 1 Or i = Len(myStr) Then Exit Function
                Case Else
                     Exit Function
            End Select
        Next i
    End If


'tests for domain portion of address (right of @)
    myStr = myArr(1)
    myArr = Split(myStr, ".")
    'test for at least one dot
    If UBound(myArr) = 0 Then Exit Function
    
'test for domain as ip address
    '(i.e. must begin and end with [] brackets, and have four numeric segments
    ' separated by dots, each segment being one to three digits.
    If Left(myStr, 1) = "[" And Right(myStr, 1) = "]" _
      And UBound(myArr) = 3 Then
        For n = 0 To 3
            myStr = myArr(n)
            myStr = Replace(myStr, "[", "")
            myStr = Replace(myStr, "]", "")
            If Len(myStr) > 3 Or Not IsNumeric(myStr) Then Exit Function
        Next n
        emailTest = True
        'full address has passed, no need to continue evaluating domain chars
        Exit Function
    End If
'continue with evaluating the domain by non-IP rules and by character compliance
    If Len(myStr) > 253 Then Exit Function
    If UBound(myArr) > 126 Then Exit Function
    For n = 0 To UBound(myArr)
        myStr = myArr(n)
        'last label (highest domain level) must be at least 2 characters
        If n = UBound(myArr) And Len(myStr) < 2 Then Exit Function
        For i = 1 To Len(myStr)
            MyChar = Mid(myStr, i, 1)
            Select Case MyChar
                Case 0 To 9, "a" To "z", "A" To "Z"
                Case "-"
                    'hyphen char may be in middle but not begining or end of label
                    If i = 1 Or i = Len(myStr) Then Exit Function
                Case Else
                    Exit Function
            End Select
        Next i
    Next n
    
    emailTest = True
    
End Function
[Modificato da duccio.73 09/05/2022 10:18]
---
pensa bene a quello che cerchi, allega un file di esempio, prova il registratore di macro, imparerai e potresti già avere la soluzione
Post: 1
Registrato il: 14/07/2018
Città: MILANO
Età: 57
Utente Junior
excell 2010
OFFLINE
09/05/2022 13:52

Ho molto da studiare.
Grazie infinite Duccio,
Hai ragione! Potevo allegare il mio progetto/file.
E' per un piccolo progetto, con inserimento tramite maschera Userform.
L'esempio che mi hai inviato è più che sufficiente e di sicuro studierò più a fondo VBA.
Grazie infinite⏳
Vota: 15MediaObject5,0013 1
Amministra Discussione: | Chiudi | Sposta | Cancella | Modifica | Notifica email Pagina precedente | 1 | Pagina successiva
Nuova Discussione
 | 
Rispondi
Cerca nel forum
Tag discussione
Discussioni Simili   [vedi tutte]
Feed | Forum | Bacheca | Album | Utenti | Cerca | Login | Registrati | Amministra
Tutti gli orari sono GMT+01:00. Adesso sono le 02:40. Versione: Stampabile | Mobile | Regolamento | Privacy
FreeForumZone [v.6.1] - Copyright © 2000-2024 FFZ srl - www.freeforumzone.com