Condividi:        

[Excel 2013] Variabile non definita

Vuoi potenziare i tuoi documenti Word? Non sai come si fa una macro in Excel? Devi creare una presentazione in PowerPoint?
Oppure sei passato a OpenOffice e non sei sicuro di come lavorare al meglio?

Moderatori: Anthony47, Flash30005

[Excel 2013] Variabile non definita

Postdi fastbike73 » 20/11/14 18:11

Buonasera, avrei questo problema.
Ho modificato la Userform impostandola "a tutto schermo" all'avvio del file e nascondendo quindi i fogli dietro la userform.
Adesso però mi da un errore di "Variabile non definita" quando provo a fare la ricerca, digitando per intero o parzialmente il numero cartella.

Il debug mi riporta a questa riga di codice...(in grassetto e sottolineato)... mi sto dimenticando qualcosina??

Private Sub CommandButton1_Click()
If TextBox1 = "" Then
MsgBox "Inserisci il numero della Cartella"
TextBox1.SetFocus
Exit Sub
End If
If OptionButton1.Value = True Then
primo
End If

If OptionButton2.Value = True Then
With ActiveSheet.Range("B3:B302")
Dim X As String
X = TextBox1.Value
Set C = .Find(X, LookIn:=xlValues) ', LookAt:=xlWhole
If Not C Is Nothing Then
firstAddress = C.Address
Do
C.Cells.Select
TextBox2 = C.Value
TextBox3 = C.Offset(0, 1).Value
TextBox4 = C.Offset(0, 2).Value
TextBox5 = C.Offset(0, 3).Value
....
fastbike73
Win 10 & Office365
Filemaker Pro v. 13
fastbike73
Utente Senior
 
Post: 256
Iscritto il: 23/04/14 10:54

Sponsor
 

Re: [Excel 2013] Variabile non definita

Postdi Anthony47 » 20/11/14 21:56

Hai impostato Option Explicit in testa al tuo Modulo, o tra le impostazioni vba (Menu /strumenti /Opzioni, tab Editor, voce "Dichiarazione di variabili obbligatoria")?
Comunque prova modificando Dim X As String in
Dim X As String, C
Avatar utente
Anthony47
Moderatore
 
Post: 19181
Iscritto il: 21/03/06 16:03
Località: Ivrea

Re: [Excel 2013] Variabile non definita

Postdi fastbike73 » 21/11/14 08:34

Anthony47 ha scritto:Hai impostato Option Explicit in testa al tuo Modulo, o tra le impostazioni vba (Menu /strumenti /Opzioni, tab Editor, voce "Dichiarazione di variabili obbligatoria")?


Buongiorno Anthony, ti ringrazio intanto per la risposta. L'option explicit è in testa al modulo, si seguito ti riporto tutto il codice della Userform.

Codice: Seleziona tutto
Option Explicit

Dim myForm As New Classe1
Dim bChiusura As Boolean


Private Sub ComboBox1_Change()
TextBox1.Text = ComboBox1.Text

End Sub

Private Sub CommandButton1_Click()
If TextBox1 = "" Then
MsgBox "Inserisci il numero della Cartella"
TextBox1.SetFocus
Exit Sub
End If
If OptionButton1.Value = True Then
primo
End If

If OptionButton2.Value = True Then
With ActiveSheet.Range("B3:B302")
Dim X As String
X = TextBox1.Value
Set C = .Find(X, LookIn:=xlValues) ', LookAt:=xlWhole
If Not C Is Nothing Then
firstAddress = C.Address
Do
C.Cells.Select
TextBox2 = C.Value
TextBox3 = C.Offset(0, 1).Value
TextBox4 = C.Offset(0, 2).Value
TextBox5 = C.Offset(0, 3).Value
TextBox6 = C.Offset(0, 4).Value
TextBox7 = C.Offset(0, 5).Value
TextBox8 = C.Offset(0, 6).Value
TextBox9 = C.Offset(0, 7).Value
TextBox10 = C.Offset(0, 8).Value
TextBox21 = C.Offset(0, 9).Value
TextBox11 = C.Offset(0, 10).Value
TextBox12 = C.Offset(0, 11).Value
TextBox13 = C.Offset(0, 12).Value
TextBox14 = C.Offset(0, 13).Value
TextBox15 = C.Offset(0, 14).Value
TextBox16 = C.Offset(0, 15).Value
TextBox17 = C.Offset(0, 16).Value
TextBox18 = C.Offset(0, 17).Value
TextBox19 = C.Offset(0, 18).Value
TextBox20 = C.Offset(0, 19).Value
TextBox22 = C.Offset(0, 20).Value
TextBox23 = C.Offset(0, 21).Value
TextBox24 = C.Offset(0, 22).Value
TextBox25 = C.Offset(0, 23).Value
TextBox26 = C.Offset(0, 24).Value
Y = C.Value
irisposta = MsgBox("Trovata " & Y & " . Vuoi fermarti ?", vbYesNo)
If irisposta = vbYes Then 'se rispondo si allora
GoTo 10 'esco dal ciclo
End If
Set C = .FindNext(C)
Loop While Not C Is Nothing And C.Address <> firstAddress

Else
MsgBox "Cartella non trovata"
End If
10:
End With
End If
End Sub

Private Sub CommandButton2_Click()
If TextBox2 = "" Then
MsgBox "Devi inserire il numero della Cartella"
TextBox2.SetFocus
Exit Sub
End If
Dim irisposta As Integer
irisposta = MsgBox("Confermi la registrazione" _
& " di " & TextBox2.Value & " ?", vbYesNo)
If irisposta = vbYes Then
Range("B1").Value = "-"
Range("B1").End(xlDown).Offset(1, 0).Select
ActiveCell.Value = TextBox2
ActiveCell.Offset(0, 1).Value = TextBox3
ActiveCell.Offset(0, 2).Value = TextBox4
ActiveCell.Offset(0, 3).Value = TextBox5
ActiveCell.Offset(0, 4).Value = TextBox6
ActiveCell.Offset(0, 5).Value = TextBox7
ActiveCell.Offset(0, 6).Value = TextBox8
ActiveCell.Offset(0, 7).Value = TextBox9
ActiveCell.Offset(0, 8).Value = TextBox10
ActiveCell.Offset(0, 9).Value = TextBox21
ActiveCell.Offset(0, 10).Value = TextBox11
ActiveCell.Offset(0, 11).Value = TextBox12
ActiveCell.Offset(0, 12).Value = TextBox13
ActiveCell.Offset(0, 13).Value = TextBox14
ActiveCell.Offset(0, 14).Value = TextBox15
ActiveCell.Offset(0, 15).Value = TextBox16
ActiveCell.Offset(0, 16).Value = TextBox17
ActiveCell.Offset(0, 17).Value = TextBox18
ActiveCell.Offset(0, 18).Value = TextBox19
ActiveCell.Offset(0, 19).Value = TextBox20
ActiveCell.Offset(0, 20).Value = TextBox22
ActiveCell.Offset(0, 21).Value = TextBox23
ActiveCell.Offset(0, 22).Value = TextBox24
ActiveCell.Offset(0, 23).Value = TextBox25
ActiveCell.Offset(0, 24).Value = TextBox26
MsgBox "Registrazione eseguita!!"
TextBox2 = ""
TextBox3 = ""
TextBox4 = ""
TextBox5 = ""
TextBox6 = ""
TextBox7 = ""
TextBox8 = ""
TextBox9 = ""
TextBox10 = ""
TextBox21 = ""
TextBox11 = ""
TextBox12 = ""
TextBox13 = ""
TextBox14 = ""
TextBox15 = ""
TextBox16 = ""
TextBox17 = ""
TextBox18 = ""
TextBox19 = ""
TextBox20 = ""
TextBox22 = ""
TextBox23 = ""
TextBox24 = ""
TextBox25 = ""
TextBox26 = ""
End If
End Sub

Private Sub CommandButton3_Click()
If TextBox2 = "" Then
MsgBox "Devi cercare una Cartella per usare il pulsante modifica"
Exit Sub
End If
ActiveCell.Value = TextBox2
ActiveCell.Offset(0, 1).Value = TextBox3
ActiveCell.Offset(0, 2).Value = TextBox4
ActiveCell.Offset(0, 3).Value = TextBox5
ActiveCell.Offset(0, 4).Value = TextBox6
ActiveCell.Offset(0, 5).Value = TextBox7
ActiveCell.Offset(0, 6).Value = TextBox8
ActiveCell.Offset(0, 7).Value = TextBox9
ActiveCell.Offset(0, 8).Value = TextBox10
ActiveCell.Offset(0, 9).Value = TextBox21
ActiveCell.Offset(0, 10).Value = TextBox11
ActiveCell.Offset(0, 11).Value = TextBox12
ActiveCell.Offset(0, 12).Value = TextBox13
ActiveCell.Offset(0, 13).Value = TextBox14
ActiveCell.Offset(0, 14).Value = TextBox15
ActiveCell.Offset(0, 15).Value = TextBox16
ActiveCell.Offset(0, 16).Value = TextBox17
ActiveCell.Offset(0, 17).Value = TextBox18
ActiveCell.Offset(0, 18).Value = TextBox19
ActiveCell.Offset(0, 19).Value = TextBox20
ActiveCell.Offset(0, 20).Value = TextBox22
ActiveCell.Offset(0, 21).Value = TextBox23
ActiveCell.Offset(0, 22).Value = TextBox24
ActiveCell.Offset(0, 23).Value = TextBox25
ActiveCell.Offset(0, 24).Value = TextBox26
MsgBox "Ok! Eseguito!"
End Sub

Private Sub CommandButton4_Click()
If TextBox2 = "" Then Exit Sub
ActiveCell.Select
Dim irisposta As Integer
irisposta = MsgBox("Vuoi cancellare la Cartella nr.: " & ActiveCell.Value & "?", vbYesNo)
If irisposta = vbYes Then
ActiveCell.EntireRow.Delete

Dim CA As Object
Range("A3:A302").ClearContents
Range("A3").Value = 1
For Each CA In Range("A3:A302")
If CA.Offset(1, 0) = "" Then
CA.Offset(1, 0) = CA + 1
End If
Next

End If
End Sub

Private Sub CommandButton5_Click()
If ActiveCell.Offset(-1, 0).Value = "Nr.cartella" Then
MsgBox "Inizio elenco"
Exit Sub
End If

ActiveCell.Offset(-1, 0).Select
TextBox2 = ActiveCell.Offset(0, 0).Value
TextBox3 = ActiveCell.Offset(0, 1).Value
TextBox4 = ActiveCell.Offset(0, 2).Value
TextBox5 = ActiveCell.Offset(0, 3).Value
TextBox6 = ActiveCell.Offset(0, 4).Value
TextBox7 = ActiveCell.Offset(0, 5).Value
TextBox8 = ActiveCell.Offset(0, 6).Value
TextBox9 = ActiveCell.Offset(0, 7).Value
TextBox10 = ActiveCell.Offset(0, 8).Value
TextBox21 = ActiveCell.Offset(0, 9).Value
TextBox11 = ActiveCell.Offset(0, 10).Value
TextBox12 = ActiveCell.Offset(0, 11).Value
TextBox13 = ActiveCell.Offset(0, 12).Value
TextBox14 = ActiveCell.Offset(0, 13).Value
TextBox15 = ActiveCell.Offset(0, 14).Value
TextBox16 = ActiveCell.Offset(0, 15).Value
TextBox17 = ActiveCell.Offset(0, 16).Value
TextBox18 = ActiveCell.Offset(0, 17).Value
TextBox19 = ActiveCell.Offset(0, 18).Value
TextBox20 = ActiveCell.Offset(0, 19).Value
TextBox22 = ActiveCell.Offset(0, 20).Value
TextBox23 = ActiveCell.Offset(0, 21).Value
TextBox24 = ActiveCell.Offset(0, 22).Value
TextBox25 = ActiveCell.Offset(0, 23).Value
TextBox26 = ActiveCell.Offset(0, 24).Value

End Sub

Private Sub CommandButton6_Click()
If ActiveCell.Offset(1, 0).Value = "" Then
MsgBox "Fine elenco"
Exit Sub
End If
ActiveCell.Offset(1, 0).Select
TextBox2 = ActiveCell.Value
TextBox3 = ActiveCell.Offset(0, 1).Value
TextBox4 = ActiveCell.Offset(0, 2).Value
TextBox5 = ActiveCell.Offset(0, 3).Value
TextBox6 = ActiveCell.Offset(0, 4).Value
TextBox7 = ActiveCell.Offset(0, 5).Value
TextBox8 = ActiveCell.Offset(0, 6).Value
TextBox9 = ActiveCell.Offset(0, 7).Value
TextBox10 = ActiveCell.Offset(0, 8).Value
TextBox21 = ActiveCell.Offset(0, 9).Value
TextBox11 = ActiveCell.Offset(0, 10).Value
TextBox12 = ActiveCell.Offset(0, 11).Value
TextBox13 = ActiveCell.Offset(0, 12).Value
TextBox14 = ActiveCell.Offset(0, 13).Value
TextBox15 = ActiveCell.Offset(0, 14).Value
TextBox16 = ActiveCell.Offset(0, 15).Value
TextBox17 = ActiveCell.Offset(0, 16).Value
TextBox18 = ActiveCell.Offset(0, 17).Value
TextBox19 = ActiveCell.Offset(0, 18).Value
TextBox20 = ActiveCell.Offset(0, 19).Value
TextBox22 = ActiveCell.Offset(0, 20).Value
TextBox23 = ActiveCell.Offset(0, 21).Value
TextBox24 = ActiveCell.Offset(0, 22).Value
TextBox25 = ActiveCell.Offset(0, 23).Value
TextBox26 = ActiveCell.Offset(0, 24).Value

End Sub

Private Sub CommandButton7_Click()
End
End Sub

Private Sub CommandButton8_Click()
TextBox1 = ""
TextBox2 = ""
TextBox3 = ""
TextBox4 = ""
TextBox5 = ""
TextBox6 = ""
TextBox7 = ""
TextBox8 = ""
TextBox9 = ""
TextBox10 = ""
TextBox21 = ""
TextBox11 = ""
TextBox12 = ""
TextBox13 = ""
TextBox14 = ""
TextBox15 = ""
TextBox16 = ""
TextBox17 = ""
TextBox18 = ""
TextBox19 = ""
TextBox20 = ""
TextBox22 = ""
TextBox23 = ""
TextBox24 = ""
TextBox25 = ""
TextBox26 = ""
ComboBox1 = ""

End Sub

Private Sub CommandButton9_Click()

Dim FN As String

FN = Application.GetOpenFilename("All files (*.*), *.*")

If FN = "Falso" Then Exit Sub

TextBox21.Text = FN

End Sub


Private Sub TextBox11_afterupdate()
TextBox11 = Format(TextBox11, "€ #,###.00")

End Sub

Private Sub TextBox12_afterupdate()
TextBox12 = Format(TextBox12, "€ #,###.00")
End Sub

Private Sub TextBox13_afterupdate()
TextBox13 = Format(TextBox13, "€ #,###.00")
End Sub

Private Sub TextBox14_afterupdate()
TextBox14 = Format(TextBox14, "€ #,###.00")
End Sub

Private Sub TextBox15_afterupdate()
TextBox15 = Format(TextBox15, "€ #,###.00")
End Sub

Private Sub TextBox16_afterupdate()
TextBox16 = Format(TextBox16, "€ #,###.00")
End Sub

Private Sub TextBox17_afterupdate()
TextBox17 = Format(TextBox17, "€ #,###.00")
End Sub

Private Sub TextBox18_afterupdate()
TextBox18 = Format(TextBox18, "€ #,###.00")
End Sub

Private Sub TextBox19_afterupdate()
TextBox19 = Format(TextBox19, "€ #,###.00")
End Sub

Private Sub TextBox20_afterupdate()
TextBox20 = Format(TextBox20, "€ #,###.00")
End Sub

Private Sub TextBox25_afterupdate()
TextBox25 = Format(TextBox25, "dd/mm/yyyy")
End Sub

Private Sub TextBox26_afterupdate()
TextBox26 = Format(TextBox26, "€ #,###.00")
End Sub

Private Sub TextBox4_afterupdate()
TextBox4 = Format(TextBox4, "dd/mm/yyyy")
End Sub

Private Sub UserForm_Initialize()

Set myForm.Form = Me
With Me
    .BorderStyle = fmBorderStyleSingle
End With
With Application
    .DisplayAlerts = False
    .WindowState = xlMaximized
End With
With Application
    Me.Top = .Top
    Me.Left = .Left
    Me.Height = .Height
    Me.Width = .Width
End With

Me.MultiPage1.Value = 0
Worksheets("Foglio1").Range("B3").Select
ComboBox1.RowSource = "B3:B302"


End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    If bChiusura = False Then
        Cancel = False
        ThisWorkbook.Save
        Application.Quit
        ThisWorkbook.Close
    ElseIf bChiusura = True Then
        Cancel = False
    End If
End Sub

Private Sub Userform_Terminate()
    Set myForm = Nothing
End Sub
fastbike73
Win 10 & Office365
Filemaker Pro v. 13
fastbike73
Utente Senior
 
Post: 256
Iscritto il: 23/04/14 10:54

Re: [Excel 2013] Variabile non definita

Postdi fastbike73 » 21/11/14 08:38

Anthony47 ha scritto:Comunque prova modificando Dim X As String in
Dim X As String, C


Ho fatto la correzione, ma l'errore si sposta più avanti... in questa riga di codice (colore rosso):

Private Sub CommandButton1_Click()
If TextBox1 = "" Then
MsgBox "Inserisci il numero della Cartella"
TextBox1.SetFocus
Exit Sub
End If
If OptionButton1.Value = True Then
primo
End If

If OptionButton2.Value = True Then
With ActiveSheet.Range("B3:B302")
Dim X As String, C
X = TextBox1.Value
Set C = .Find(X, LookIn:=xlValues) ', LookAt:=xlWhole
If Not C Is Nothing Then
firstAddress = C.Address
fastbike73
Win 10 & Office365
Filemaker Pro v. 13
fastbike73
Utente Senior
 
Post: 256
Iscritto il: 23/04/14 10:54

Re: [Excel 2013] Variabile non definita

Postdi Anthony47 » 21/11/14 13:19

Se hai attivato Option Explicit allora devi esplicitamente dichiarare tutte le variabili che usi, tramite l' istruzione Dim
Se non sai il "data type", limitati a dichiarare il nome senza altri attributi, e automaticamente sara' una Variant.
Es:
Codice: Seleziona tutto
Dim X, C, FirstAddress

Per la sintassi di Dim e il significato dei vari data type ti aiutera' l' help on line del vba.

Ciao
Avatar utente
Anthony47
Moderatore
 
Post: 19181
Iscritto il: 21/03/06 16:03
Località: Ivrea

Re: [Excel 2013] Variabile non definita

Postdi fastbike73 » 21/11/14 15:31

Anthony, ti ringrazio. Ho dichiarato tutte le variabili e successivamente ha funzionato tutto alla perfezione.
fastbike73
Win 10 & Office365
Filemaker Pro v. 13
fastbike73
Utente Senior
 
Post: 256
Iscritto il: 23/04/14 10:54


Torna a Applicazioni Office Windows


Topic correlati a "[Excel 2013] Variabile non definita":


Chi c’è in linea

Visitano il forum: Nessuno e 57 ospiti

cron