
Sub Test()
Dim cf As String
cf = "AAABBB71E67E111P"
If Verifica_CF_Form(cf) Then
Debug.Print DataDaCF(cf)
End If
End Sub
Function DataDaCF(cf As String) As Date
Dim Y As Long, D As Long, M As Long, sM As String
Dim arrM
arrM = Array("A", "B", "C", "D", "E", "H", "L", "M", "P", "R", "S", "T")
Y = CLng(Mid(cf, 7, 2))
If Y < Year(Date) - 2000 Then
Y = Y + 2000
Else
Y = Y + 1900
End If
sM = Mid(cf, 9, 1)
For D = 0 To 11
If sM = arrM(D) Then
M = D + 1
Exit For
End If
Next
D = CLng(Mid(cf, 10, 2))
If D > 31 Then
D = D - 40
End If
DataDaCF = DateSerial(Y, M, D)
End Function
Public Function Verifica_CF_Form( _
testo As String) As Boolean
Dim RE As Object
Set RE = CreateObject("VBScript.RegExp")
RE.Global = True
RE.Pattern = _
"^([A-Z]{6})" & _
"(d{2})" & _
"([A-EHLMPR-T]{1})" & _
"(70|71|[0-6]{1}d{1})" & _
"([A-Z]{1})([0-9L-NPQ-V]{3})" & _
"([A-Z]{1})$"
Verifica_CF_Form = RE.Test(testo)
End Function
|
Sub estrai() Dim a As String Dim tutto As String Dim giorno As String Dim mese As String Dim anno As String a = Cells(1, 1) tutto = mid(a, 7, 5) anno = mid(tutto, 1, 2) mese = mid(tutto, 3, 1) giorno = mid(tutto, 4, 2) If mese = "a" Or mese = "A" Then mese = "01" ElseIf mese = "b" Or mese = "B" Then mese = "02" ElseIf mese = "c" Or mese = "C" Then mese = "03" ElseIf mese = "d" Or mese = "D" Then mese = "04" ElseIf mese = "e" Or mese = "E" Then mese = "05" ElseIf mese = "h" Or mese = "H" Then mese = "06" ElseIf mese = "l" Or mese = "L" Then mese = "07" ElseIf mese = "m" Or mese = "M" Then mese = "08" ElseIf mese = "p" Or mese = "P" Then mese = "09" ElseIf Cells(1, 4) = "r" Or mese = "R" Then mese = "10" ElseIf Cells(1, 4) = "s" Or mese = "S" Then mese = "11" ElseIf Cells(1, 4) = "t" Or mese = "T" Then mese = "12" End If If giorno > 40 Then giorno = giorno - 40 End If Cells(1, 2).Value = giorno & "/" & mese & "/" & anno End Sub |
Sub estrai()
Dim i As Integer
Dim a As String
Dim tutto As String
Dim giorno As String
Dim mese As String
Dim anno As String
Range("A1").Select
Do While Selection.Value <> ""
a = ActiveCell.Value
tutto = Mid(a, 7, 5)
anno = Mid(tutto, 1, 2)
mese = Mid(tutto, 3, 1)
giorno = Mid(tutto, 4, 2)
If mese = "a" Or mese = "A" Then
mese = "01"
ElseIf mese = "b" Or mese = "B" Then
mese = "02"
ElseIf mese = "c" Or mese = "C" Then
mese = "03"
ElseIf mese = "d" Or mese = "D" Then
mese = "04"
ElseIf mese = "e" Or mese = "E" Then
mese = "05"
ElseIf mese = "h" Or mese = "H" Then
mese = "06"
ElseIf mese = "l" Or mese = "L" Then
mese = "07"
ElseIf mese = "m" Or mese = "M" Then
mese = "08"
ElseIf mese = "p" Or mese = "P" Then
mese = "09"
ElseIf mese = "r" Or mese = "R" Then
mese = "10"
ElseIf mese = "s" Or mese = "S" Then
mese = "11"
ElseIf mese = "t" Or mese = "T" Then
mese = "12"
End If
If giorno > 40 Then
giorno = giorno - 40
End If
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = giorno & "/" & mese & "/" & anno
ActiveCell.Offset(1, -1).Range("A1").Select
Loop
End Sub
|
