Spiego brevemente lo scopo del lavoro.
Sto creando una maschera, in
Visual Basic for Application, in cui inserendo dei dati in opportune ComboBox/TextBox e cliccando su un Command Button vengono direttamente caricati in un altro file excel; contemporaneamente si creano cartelle e sottocartelle in una determinata
directory. Visto che la maggior parte dei dati sono obbligatori, ho dovuto utilizzare un'istruzione “If..then..elseif..else..end if” abbastanza lunga, che non mi permette di andare avanti nel caricamento dei dati nell’atro file excel se i campi obbligatori
non vengono inseriti.
Il mio
problema è il seguente:
dopo 5/6 volte che cerco di caricare i dati (i dati sono obbligatori ma li ho lasciati vuoti perché sto in fase di prova e quindi voglio trovare tutti
i possibili errori) la UserForm (o meglio la maschera in cui si inseriscono i dati) si blocca e non mi permette di cliccare su nessun TextBox, ComboBox o Command Button….e l’unica cosa che posso fare è chiudere il file excel in cui ho creato la maschera.
PS: il programmino non mi da errori; quindi non capisco dove ho sbagliato il codice visto che sto
usando Visaul Basic da una decina di giorni!!
Questo l'intero codice, di tutte le le textbox/combobox/command button:
Private Sub ComboBox10_DropButtonClick()
Me.ComboBox10.List = Application.Transpose(Range("BS7:BU7"))
End Sub
Private Sub ComboBox11_DropButtonClick()
Me.ComboBox11.List = Application.Transpose(Range("BS7:BU7"))
End Sub
Private Sub ComboBox12_DropButtonClick()
Me.ComboBox12.List = Application.Transpose(Range("BS7:BU7"))
End Sub
Private Sub ComboBox2_DropButtonClick()
Me.ComboBox2.List = Application.Transpose(Range("BS3:EG3"))
End Sub
Private Sub ComboBox3_DropButtonClick()
Me.ComboBox3.List = Application.Transpose(Range("BS4:BX4"))
End Sub
Private Sub ComboBox4_DropButtonClick()
Me.ComboBox4.List = Application.Transpose(Range("BS2:CA2"))
End Sub
Private Sub ComboBox5_DropButtonClick()
Me.ComboBox5.List = Application.Transpose(Range("BS5:BU5"))
End Sub
Private Sub ComboBox6_DropButtonClick()
Me.ComboBox6.List = Application.Transpose(Range("BS6:BV6"))
End Sub
Private Sub ComboBox7_DropButtonClick()
Me.ComboBox7.List = Application.Transpose(Range("BS7:BU7"))
End Sub
Private Sub ComboBox8_DropButtonClick()
Me.ComboBox8.List = Application.Transpose(Range("BS7:BU7"))
End Sub
Private Sub ComboBox9_DropButtonClick()
Me.ComboBox9.List = Application.Transpose(Range("BS7:BU7"))
End Sub
Private Sub CommandButton1_Click()
Unload Me
Windows("Maschera Contract Summary.xlsm").Activate
Range("A1").Select
ActiveWindow.LargeScroll ToRight:=1
Range("AB5:BH5").Select
Selection.Copy
Range("A1").Select
ActiveCell.Offset(8, 27).Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
ActiveSheet.Range("A1").Select
Application.CutCopyMode = False
ActiveWorkbook.Save
UserForm1.Show
End Sub
Private Sub CommandButton2_Click()
Unload Me
If TextBox1.Text = "" Then
MsgBox "Digitare Valore in Campo Company.", vbCritical, "Errore"
UserForm1.Show
ElseIf ComboBox5.Text = "" Then
MsgBox "Definire area procurement ID.", vbCritical, "Errore"
UserForm1.Show
ElseIf ComboBox4.Text = "" Then
MsgBox "Selezionare Valore Commodity L2.", vbCritical, "Errore"
UserForm1.Show
ElseIf ComboBox2.Text = "" Then
MsgBox "Selezionare Valore Commodity L3.", vbCritical, "Errore"
UserForm1.Show
ElseIf Not Left(Range("AD5").Value, 1) = Left(Range("AE5").Value, 1) Then
MsgBox "La Commodity L3 deve essere della stessa famiglia della Commodity L2.", vbCritical, "Errore"
UserForm1.Show
ElseIf TextBox28.Text = "" Then
MsgBox "Inserire Vendor Code.", vbCritical, "Errore"
UserForm1.Show
ElseIf TextBox26.Text = "" Then
MsgBox "Inserire Buyer Code.", vbCritical, "Errore"
UserForm1.Show
ElseIf TextBox7.Text = "" Then
MsgBox "Inserire SAP Contract Number.", vbCritical, "Errore"
UserForm1.Show
ElseIf InStr(TextBox7.Text, "/") Then
MsgBox "In SAP number non è permesso l'inserimento di /:*<>|""", vbCritical, "Errore"
UserForm1.Show
ElseIf InStr(TextBox7.Text, "") Then
MsgBox "In SAP number non è permesso l'inserimento di /:*<>|""", vbCritical, "Errore"
UserForm1.Show
ElseIf InStr(TextBox7.Text, "|") Then
MsgBox "In SAP number non è permesso l'inserimento di /:*<>|""", vbCritical, "Errore"
UserForm1.Show
ElseIf InStr(TextBox7.Text, Range("AB3").Value) Then
MsgBox "In SAP number non è permesso l'inserimento di /:*<>|""", vbCritical, "Errore"
UserForm1.Show
ElseIf InStr(TextBox7.Text, "*") Then
MsgBox "In SAP number non è permesso l'inserimento di /:*<>|""", vbCritical, "Errore"
UserForm1.Show
ElseIf InStr(TextBox7.Text, "<") Then
MsgBox "In SAP number non è permesso l'inserimento di /:*<>|""", vbCritical, "Errore"
UserForm1.Show
ElseIf InStr(TextBox7.Text, ">") Then
MsgBox "In SAP number non è permesso l'inserimento di /:*<>|""", vbCritical, "Errore"
UserForm1.Show
ElseIf InStr(TextBox7.Text, ":") Then
MsgBox "In SAP number non è permesso l'inserimento di /:*<>|""", vbCritical, "Errore"
UserForm1.Show
ElseIf ComboBox3.Text = "" Then
MsgBox "Selezionare Contract Type.", vbCritical, "Errore"
UserForm1.Show
ElseIf TextBox8.Text = "" Or TextBox8.MaxLength > 30 Then
MsgBox "Inserire Breve Descrizione [max 30 caratteri].", vbCritical, "Errore"
UserForm1.Show
ElseIf InStr(TextBox8.Text, "") Then
MsgBox "In Brief Description non è permesso l'inserimento di /:*<>|""", vbCritical, "Errore"
UserForm1.Show
ElseIf InStr(TextBox8.Text, "/") Then
MsgBox "In Brief Description non è permesso l'inserimento di /:*<>|""", vbCritical, "Errore"
UserForm1.Show
ElseIf InStr(TextBox8.Text, ":") Then
MsgBox "In Brief Description non è permesso l'inserimento di /:*<>|""", vbCritical, "Errore"
UserForm1.Show
ElseIf InStr(TextBox8.Text, "*") Then
MsgBox "In Brief Description non è permesso l'inserimento di /:*<>|""", vbCritical, "Errore"
UserForm1.Show
ElseIf InStr(TextBox8.Text, "<") Then
MsgBox "In Brief Description non è permesso l'inserimento di /:*<>|""", vbCritical, "Errore"
UserForm1.Show
ElseIf InStr(TextBox8.Text, ">") Then
MsgBox "In Brief Description non è permesso l'inserimento di /:*<>|""", vbCritical, "Errore"
UserForm1.Show
ElseIf InStr(TextBox8.Text, "|") Then
MsgBox "In Brief Description non è permesso l'inserimento di /:*<>|""", vbCritical, "Errore"
UserForm1.Show
ElseIf InStr(TextBox8.Text, Range("AB3").Value) Then
MsgBox "In Brief Description non è permesso l'inserimento di /:*<>|""", vbCritical, "Errore"
UserForm1.Show
ElseIf Not IsDate(TextBox9.Text) Then
MsgBox "Inserire Data in formato dd/mm/yyyy in Date of Creation.)", vbCritical, "Errore"
UserForm1.Show
ElseIf Not IsDate(TextBox11.Text) Then
MsgBox "Inserire Data in formato dd/mm/yyyy in Validity - Start Data.)", vbCritical, "Errore"
UserForm1.Show
ElseIf Not IsDate(TextBox12.Text) Then
MsgBox "Inserire Data in formato dd/mm/yyyy in Validity - End Data.)", vbCritical, "Errore"
UserForm1.Show
ElseIf Not IsNumeric(TextBox13.Text) Then
MsgBox "Inserire valore numerico in Contract Value.", vbCritical, "Errore"
UserForm1.Show
ElseIf ComboBox6.Text = "" Then
MsgBox "Campo Currency vuoto.", vbCritical, "Errore"
UserForm1.Show
ElseIf ComboBox7.Text = "" Then
MsgBox "Campo Volume Committent vuoto.", vbCritical, "Errore"
UserForm1.Show
ElseIf ComboBox11.Text = "" Then
MsgBox "Campo Escalation Formula vuoto.", vbCritical, "Errore"
UserForm1.Show
ElseIf ComboBox12.Text = "" Then
MsgBox "Campo Rebates vuoto.", vbCritical, "Errore"
UserForm1.Show
ElseIf ComboBox8.Text = "" Then
MsgBox "Campo Automatic renewal clauses vuoto.", vbCritical, "Errore"
UserForm1.Show
ElseIf ComboBox9.Text = "" Then
MsgBox "Campo Early Termination vuoto.", vbCritical, "Errore"
UserForm1.Show
ElseIf ComboBox10.Text = "" Then
MsgBox "Campo KPI vuoto.", vbCritical, "Errore"
UserForm1.Show
Else
Dim fso
Dim fol As String
fol = "C:\Users\giuseppe.divico\Desktop\Contratti" & Range("AD5").Value & "" & Range("AE5").Value & "" & Range("AG5").Value & "_" & Range("AH5").Value
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(fol) Then
fso.CreateFolder (fol)
End If
Dim fsa
Dim fal As String
fal = "C:\Users\giuseppe.divico\Desktop\Contratti" & Range("AD5").Value & "" & Range("AE5").Value & "" & Range("AG5").Value & "_" & Range("AH5").Value & "" & Range("AM5").Value & "_" & Range("AN5").Value
Set fsa = CreateObject("Scripting.FileSystemObject")
If Not fsa.FolderExists(fal) Then
fsa.CreateFolder (fal)
Else
MsgBox "Cartella già esistente. Modificare SAP Number o utilizzare un'altra descrizione breve.", vbCritical, "Errore"
UserForm1.Show
End If
Workbooks.Open Filename:="C:\Users\giuseppe.divico\Desktop\AW IP Contratti Summary Prova.xlsx"
Windows("Maschera Contract Summary.xlsm").Activate
Range("A1").Select
ActiveWindow.LargeScroll ToRight:=1
Range("AB5:BH5").Select
Selection.Copy
Windows("AW IP Contratti Summary Prova.xlsx").Activate
Range("A1").Select
ActiveCell.Offset(1, 1).Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
ActiveSheet.Range("A1").Select
Application.CutCopyMode = False
ActiveWorkbook.Save
Windows("AW IP Contratti Summary Prova.xlsx").Close
Windows("Maschera Contract Summary.xlsm").Activate
Range("A1").Select
ActiveWindow.LargeScroll ToRight:=1
Range("AB5:AG5,AI5,AK5:AS5,AU5:BF5,BH5").Select
Selection.ClearContents
Range("A1").Select
End If
End Sub
Private Sub CommandButton3_Click()
Unload Me
Range("A1").Select
ActiveWindow.LargeScroll ToRight:=1
Range("AB5:AG5,AI5,AK5:AS5,AU5:BF5,BH5").Select
Selection.ClearContents
Range("A1").Select
ActiveWindow.LargeScroll ToRight:=1
Range("AB13:AG40,AI13,AK13:AS40,AU13:BF40,BH13:BH40").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Range("A1").Select
End Sub
Private Sub Label21_Click()
End Sub
Private Sub Label23_Click()
End Sub
Private Sub Label24_Click()
End Sub
Private Sub Label26_Click()
End Sub
Private Sub Label27_Click()
End Sub
Private Sub Label30_Click()
End Sub
Private Sub TextBox1_Change()
End Sub
Private Sub TextBox11_Change()
End Sub
Private Sub TextBox12_()
End Sub
Private Sub TextBox12_Change()
End Sub
Private Sub TextBox22_Change()
End Sub
Private Sub TextBox8_Change()
End Sub
Private Sub TextBox9_Change()
End Sub
Private Sub UserForm_Click()
End Sub
Grazie in anticipo. Spero mi sono spiegato bene e che la cosa sia risolvibile.
Giuseppe