Ciao Sergio,
VBA parla solo una forma imbastardito di inglese, ossia americano, e quindi le date vengono interpretare come date nel formato ammericano
mm/gg/aaaa.
Pertanto per ovviare il problema che riscontri, nella procedura CommandButton1_Click(), potresti sostituire ili seguente comando
.Cells(lng, 6).Value = Me.TextBox5.Text
con:
.Cells(lng, 6).Value = CDate(Me.TextBox5.Text)
Comunque, se fosse per me, per abbreviarla, vorrei sostiuire la intera procedura
Private Sub CommandButton1_Click()
Dim lRisposta As Long
Dim lRiga As Long
Dim lng As Long
lRisposta = MsgBox(Prompt:="Modificare il contenuto delle celle.", _
Title:="Attenzione", _
Buttons:=vbYesNo + vbQuestion)
With sh
If lRisposta = vbYes Then
lRiga = .Range("B" & .Rows.Count).End(xlUp).Row
For lng = 2 To lRiga
If CStr(.Cells(lng, 2).Value) = Me.ComboBox1.Text Then
.Cells(lng, 1).Value = Me.TextBox1.Text
.Cells(lng, 3).Value = Me.TextBox2.Text
.Cells(lng, 4).Value = Me.TextBox3.Text
.Cells(lng, 5).Value = Me.TextBox4.Text
.Cells(lng, 6).Value = Me.TextBox5.Text
.Cells(lng, 7).Value = Me.TextBox6.Text
.Cells(lng, 8).Value = Me.TextBox7.Text
.Cells(lng, 9).Value = Me.TextBox8.Text
.Cells(lng, 10).Value = Me.TextBox9.Text
.Cells(lng, 11).Value = Me.TextBox10.Text
.Cells(lng, 12).Value = Me.TextBox11.Text
.Cells(lng, 13).Value = Me.TextBox12.Text
.Cells(lng, 14).Value = Me.TextBox13.Text
.Cells(lng, 15).Value = Me.TextBox14.Text
.Cells(lng, 16).Value = Me.TextBox15.Text
.Cells(lng, 17).Value = Me.TextBox16.Text
.Cells(lng, 18).Value = Me.TextBox17.Text
.Cells(lng, 19).Value = Me.TextBox18.Text
.Cells(lng, 20).Value = Me.TextBox19.Text
.Cells(lng, 21).Value = Me.TextBox20.Text
.Cells(lng, 22).Value = Me.TextBox21.Text
.Cells(lng, 23).Value = Me.TextBox22.Text
.Cells(lng, 24).Value = Me.TextBox23.Text
.Cells(lng, 25).Value = Me.TextBox24.Text
.Cells(lng, 26).Value = Me.TextBox25.Text
.Cells(lng, 27).Value = Me.TextBox26.Text
.Cells(lng, 28).Value = Me.TextBox27.Text
.Cells(lng, 29).Value = Me.TextBox28.Text
.Cells(lng, 30).Value = Me.TextBox29.Text
.Cells(lng, 31).Value = Me.TextBox30.Text
Exit For
End If
Next
End If
End With
End Sub
con:
'=========>>
Private Sub CommandButton1_Click()
Dim lRisposta As Long
Dim lRiga As Long
Dim lng As Long, i As Long
lRisposta = MsgBox(Prompt:="Modificare il contenuto delle celle.", _
Title:="Attenzione", _
Buttons:=vbYesNo + vbQuestion)
With sh
If lRisposta = vbYes Then
lRiga = .Range("B" & .Rows.Count).End(xlUp).Row
For lng = 2 To lRiga
If CStr(.Cells(lng, 2).Value) = Me.ComboBox1.Text Then
i = lng - (lng - 1 > 1)
For i = 1 To 30
Select Case i
Case 1: .Cells(lng, i).Value = _
Me.Controls("TextBox" & i).Text
Case 5: .Cells(lng, i + 1).Value = _
CDate(Me.Controls("TextBox" & i).Text)
Case Else: .Cells(lng, i - (i > 1)).Value = _
Me.Controls("TextBox" & i).Text
End Select
Next i
Exit For
End If
Next lng
End If
End With
End Sub
'<<=========
Potresti scaricare il mio file di prova Sergio20170914.xlsm
===
Regards,
Norman
