Ciao Norman.
Innanzi tutto grazie per la risposta.
Non so però come integrare i tuoi codici a quello che ho già io...
Nella mia USERFORM ho questo codice:
Option Explicit
Private Const mcstrFoglio As String = "Foglio1"
Private Const mcstrStart As String = "A4"
Private Const mcstrStop As String = "A81"
Private Const mcstrColST_ As String = "A"
Private Const mcstrColOgg As String = "B"
Private Const mcstrColRFR As String = "C"
Private Const mcstrColOwn As String = "D"
Private Const mcstrColApp As String = "E"
Private Const mcstrColAmb As String = "G"
Private Const mcstrColDat As String = "H"
Private Const mcstrColNot As String = "L"
Private mblnQuitOnClose As Boolean
Private Sub cmdInserisci_Click()
On Error GoTo ExtP
Dim wbk As Excel.Workbook
Dim wsh As Excel.Worksheet
Dim r As Long
Dim ctl As MSForms.Control
Set wbk = Excel.Application.ThisWorkbook
Set wsh = wbk.Worksheets(mcstrFoglio)
With wsh
r = .Range(mcstrStop).End(xlUp).Row + 1
If r = .Range(mcstrStart).Row Then
MsgBox "L'area dati è piena.", _
vbOKOnly Or vbExclamation, _
"Inserisci"
Else
.Range(mcstrColST_ & r).Value = Me.txtST.Value
.Range(mcstrColOgg & r).Value = Me.txtoggetto.Value
.Range(mcstrColRFR & r).Value = Me.txtRFR.Value
.Range(mcstrColOwn & r).Value = Me.cboowner.Value
.Range(mcstrColApp & r).Value = Me.cboapplicativo.Value
.Range(mcstrColAmb & r).Value = Me.cboambiente.Value
.Range(mcstrColDat & r).Value = Me.cbodata.Value
.Range(mcstrColNot & r).Value = Me.txtnote.Value
End If
End With
With Me
For Each ctl In .Controls
With ctl
If TypeName(ctl) = "CommandButton" Then
If ctl Is Me.cmdNew Then
.Enabled = True
.SetFocus
End If
Else
.Enabled = False
End If
End With
Next
.cmdInserisci.Enabled = False
End With
ExtP:
With Err
If .Number Then MsgBox .Description, _
vbOKOnly Or vbCritical, _
"ERRORE#" & .Number
End With
On Error Resume Next
Set ctl = Nothing
Set wsh = Nothing
Set wbk = Nothing
End Sub
Private Sub cmdNew_Click()
Dim ctl As MSForms.Control
With Me
For Each ctl In .Controls
With ctl
If TypeName(ctl) = "CommandButton" Then
If ctl Is Me.cmdInserisci Then .Enabled = True
Else
Select Case TypeName(ctl)
Case "ComboBox", "TextBox"
.Enabled = True
.Value = Null
Case "Label"
.Enabled = True
Case Else
' DO NOTHING
End Select
End If
End With
Next
.cmdNew.Enabled = False
.txtST.SetFocus
End With
Set ctl = Nothing
End Sub
Private Sub UserForm_Initialize()
Dim rng As Excel.Range
For Each rng In ThisWorkbook.Worksheets("Foglio1").Range("Z83:Z89")
Me.cbodata.AddItem VBA.FORMAT$(rng.Value, "dd/mm/yyyy")
Next
Set rng = Nothing
With Me
.BorderStyle = fmBorderStyleSingle
End With
'interrompo eventuali Alert e ridimensiono
'a tutto schermo il file di Excel
With Application
.DisplayAlerts = False
.WindowState = xlMaximized
End With
'ridimensiono la UserForm
With Application
Me.Top = .Top
Me.Left = .Left
Me.Height = .Height
Me.Width = .Width
End With
End Sub
Private Sub cmdTEST_Click()
Unload Me
End Sub
Private Sub cmdQuit_Click()
mblnQuitOnClose = True
Unload Me
End Sub
Private Sub UserForm_Terminate()
If mblnQuitOnClose Then
With ThisWorkbook
If Not .Saved Then .Save
.Application.Quit
End With
End If
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) 'Disabilita la X di dx
If CloseMode = vbFormControlMenu Then
Cancel = True
End If
End Sub
Mentre nel modulo deduco che devo copiare così com'è il tuo codice giusto?
Se mi puoi aiutare con il codice della USERFORM te ne sarei grato.
Massimo