| | Post: 74 | Registrato il: 18/06/2010
| Città: LUGO | Età: 70 | Utente Junior | Excell 2016 | | OFFLINE | |
|
07/08/2020 12:27 | |
Scusate se ne approfitto , ma mi servirebbe un consiglio :
Ho una UserForm con 4 TextBox che mi servono per aggiornare 4 valori
sul foglio1 alle celle A2,B2,C2,D2. Ora vorrei sapere come posso modificare il mio codice (allego es.) per far si che se inserisco solo due dati (es.Dato C e Dato D) mi aggiorni solo le celle C2 e D2
Grazie per l'attenzione |
|
| | Post: 2.944 | Registrato il: 06/04/2013
| Utente Veteran | 2010 | | OFFLINE |
|
07/08/2020 12:58 | |
ciao
non ci sono nè user form nè codici nel tuo allegato
Comunque, in linea di massima:
if me.txtbox1 <> "" then
valorizza cella
etc
etc
[Modificato da dodo47 07/08/2020 13:02] Domenico
Win 10 - Excel 2016 |
| | Post: 75 | Registrato il: 18/06/2010
| Città: LUGO | Età: 70 | Utente Junior | Excell 2016 | | OFFLINE | |
|
07/08/2020 14:03 | |
Scusa dodo47 ma naturalmente avevo salvato il file senza attivazione macro ... questo è il mio codice |
| | Post: 76 | Registrato il: 18/06/2010
| Città: LUGO | Età: 70 | Utente Junior | Excell 2016 | | OFFLINE | |
|
07/08/2020 14:58 | |
mi segnala errore sulla riga B=TextBox2 , dove sbaglio ???
grazieee
Private Sub CommandButton1_Click()
Dim A As Double, B As Double, C As Double, D As Double
A = TextBox1
B = TextBox2
C = TextBox3
D = TextBox4
Riga = 2
If Me.TextBox1 <> "" Then
Cells(Riga, 1) = A
End If
If Me.TextBox2 <> "" Then
Cells(Riga, 2) = B
End If
If Me.TextBox3 <> "" Then
Cells(Riga, 3) = C
End If
If Me.TextBox4 <> "" Then
Cells(Riga, 4) = D
End If
TextBox1 = ""
TextBox2 = ""
TextBox3 = ""
TextBox4 = ""
End Sub
|
| | Post: 821 | Registrato il: 24/06/2015
| Città: CATANIA | Età: 80 | Utente Senior | Excel2019 | | OFFLINE |
|
07/08/2020 16:01 | |
Ciao
sostituisci la macro collegata al pulsante Inserisci della UserForm quest'altra
Private Sub CommandButton1_Click()
Dim A As Double, B As Double, C As Double, D As Double
If TextBox1 <> "" Then A = TextBox1 Else A = Cells(2, 1).Value
If TextBox2 <> "" Then B = TextBox2 Else B = Cells(2, 2).Value
If TextBox3 <> "" Then C = TextBox3 Else C = Cells(2, 3).Value
If TextBox4 <> "" Then D = TextBox4 Else D = Cells(2, 4).Value
Cells(2, 1) = A
Cells(2, 2) = B
Cells(2, 3) = C
Cells(2, 4) = D
TextBox1 = ""
TextBox2 = ""
TextBox3 = ""
TextBox4 = ""
End Sub
Fai attenzione a NON utilizzare il punto del tastierino numerico.
Fai sapere. Ciao,
Mario |
| | Post: 2.945 | Registrato il: 06/04/2013
| Utente Veteran | 2010 | | OFFLINE |
|
07/08/2020 16:09 | |
Ciao
le TextBox per natura sono testi, pertanto se dichiari Double una variabile e nella txtBox non ci metti nulla, excel va in errore perchè si aspetta un numero e non "" (vuoto).
Cambia le dim in Variant
Poi, visto che ci sei, che scopo ha assegnare ad A-B-C-D i valori delle TextBox e poi fare (per esempio): If Me.TextBox1 <> "" Then ??; fai semplicemente : If A <> "" ...., pertanto:
Private Sub CommandButton1_Click()
Dim A As Variant, B As Variant, C As Variant, D As Variant
A = TextBox1
B = TextBox2
C = TextBox3
D = TextBox4
Riga = 2
If A <> "" Then Cells(Riga, 1) = A
If B <> "" Then Cells(Riga, 2) = B
If C <> "" Then Cells(Riga, 3) = C
If D <> "" Then Cells(Riga, 4) = D
TextBox1 = ""
TextBox2 = ""
TextBox3 = ""
TextBox4 = ""
End Sub
Saluti
[Modificato da dodo47 07/08/2020 16:13] Domenico
Win 10 - Excel 2016 |
| | Post: 77 | Registrato il: 18/06/2010
| Città: LUGO | Età: 70 | Utente Junior | Excell 2016 | | OFFLINE | |
|
07/08/2020 18:35 | |
Ho testato tutti due i metodi, sono perfetti entrambi.
Grazie Marius44 👏👏
Grazie dodo47 👏👏
[RISOLTO] |
|
|