Saltar al contenido

Saludos, Como puedo resumir este codigo? Muchas Gracias


Recommended Posts

publicado

Saludos, soy muy nuevo, reciente, en la programacion con VBA de Excel, es muy apasionante, pero como todo que comienza debe ser investigado y aprendido, por favor, el codigo adjunto funciona bien, solo quisiera saber como resumirlo, Muchisimas gracias.

Ademas, desearia saber como escribir texto en un textbox, al dar enter pasa a otro textbox, al enter otra vez pasar estos textos a la hoja de calculo y verlos tipo lista en un tercer textbox del mismo userform, me explico? introducir datos en dos textbox consecutivamente, al dar enter en el segundo pasaran los datos a la hoja de calculo y reflejados en el tercer textbox, se retorna al textbox 1 de nuevo y se repite la entrada de datos, los nuevos datos seran escritos consecutivamente en el tercer textbox y en la hoja de calculo, llenando celdas en dos columnas, tipo lista que se va llenando.

Muchas Gracias

Private Sub CommandButton11_Click()        
If ToggleButton1.Value = True Then ToggleButton1.Value = False
If ToggleButton2.Value = True Then ToggleButton2.Value = False
If ToggleButton3.Value = True Then ToggleButton3.Value = False
If ToggleButton4.Value = True Then ToggleButton4.Value = False
If ToggleButton5.Value = True Then ToggleButton5.Value = False
If ToggleButton6.Value = True Then ToggleButton6.Value = False
If ToggleButton7.Value = True Then ToggleButton7.Value = False
If ToggleButton8.Value = True Then ToggleButton8.Value = False
If ToggleButton9.Value = True Then ToggleButton9.Value = False
If ToggleButton10.Value = True Then ToggleButton10.Value = False
If ToggleButton11.Value = True Then ToggleButton11.Value = False
If ToggleButton12.Value = True Then ToggleButton12.Value = False
If ToggleButton13.Value = True Then ToggleButton13.Value = False
If ToggleButton14.Value = True Then ToggleButton14.Value = False
If ToggleButton15.Value = True Then ToggleButton15.Value = False
If ToggleButton16.Value = True Then ToggleButton16.Value = False
If ToggleButton17.Value = True Then ToggleButton17.Value = False
If ToggleButton18.Value = True Then ToggleButton18.Value = False
If ToggleButton19.Value = True Then ToggleButton19.Value = False
If ToggleButton20.Value = True Then ToggleButton20.Value = False
If ToggleButton21.Value = True Then ToggleButton21.Value = False
If ToggleButton22.Value = True Then ToggleButton22.Value = False
If ToggleButton23.Value = True Then ToggleButton23.Value = False
If ToggleButton24.Value = True Then ToggleButton24.Value = False
If ToggleButton25.Value = True Then ToggleButton25.Value = False
If ToggleButton26.Value = True Then ToggleButton26.Value = False
If ToggleButton27.Value = True Then ToggleButton27.Value = False
If ToggleButton28.Value = True Then ToggleButton28.Value = False
If ToggleButton29.Value = True Then ToggleButton29.Value = False
If ToggleButton30.Value = True Then ToggleButton30.Value = False
If ToggleButton31.Value = True Then ToggleButton31.Value = False
If ToggleButton32.Value = True Then ToggleButton32.Value = False
If ToggleButton33.Value = True Then ToggleButton33.Value = False
If ToggleButton34.Value = True Then ToggleButton34.Value = False
If ToggleButton35.Value = True Then ToggleButton35.Value = False
If ToggleButton36.Value = True Then ToggleButton36.Value = False
If ToggleButton37.Value = True Then ToggleButton37.Value = False
If ToggleButton38.Value = True Then ToggleButton38.Value = False
If ToggleButton39.Value = True Then ToggleButton39.Value = False
If ToggleButton40.Value = True Then ToggleButton40.Value = False
If ToggleButton41.Value = True Then ToggleButton41.Value = False
If ToggleButton42.Value = True Then ToggleButton42.Value = False
If ToggleButton43.Value = True Then ToggleButton43.Value = False
If ToggleButton44.Value = True Then ToggleButton44.Value = False
If ToggleButton45.Value = True Then ToggleButton45.Value = False
If ToggleButton46.Value = True Then ToggleButton46.Value = False
If ToggleButton47.Value = True Then ToggleButton47.Value = False
If ToggleButton48.Value = True Then ToggleButton48.Value = False
If ToggleButton49.Value = True Then ToggleButton49.Value = False
If ToggleButton50.Value = True Then ToggleButton50.Value = False
If ToggleButton51.Value = True Then ToggleButton51.Value = False
If ToggleButton52.Value = True Then ToggleButton52.Value = False
If ToggleButton53.Value = True Then ToggleButton53.Value = False
If ToggleButton54.Value = True Then ToggleButton54.Value = False
If ToggleButton55.Value = True Then ToggleButton55.Value = False
If ToggleButton56.Value = True Then ToggleButton56.Value = False
If ToggleButton57.Value = True Then ToggleButton57.Value = False
End Sub

Private Sub CommandButton12_Click()
If ToggleButton46.Value = False Then ToggleButton46.Value = True
If ToggleButton47.Value = False Then ToggleButton47.Value = True
If ToggleButton48.Value = False Then ToggleButton48.Value = True
If ToggleButton49.Value = False Then ToggleButton49.Value = True
If ToggleButton50.Value = False Then ToggleButton50.Value = True
If ToggleButton51.Value = False Then ToggleButton51.Value = True
If ToggleButton52.Value = False Then ToggleButton52.Value = True
If ToggleButton53.Value = False Then ToggleButton53.Value = True
If ToggleButton54.Value = False Then ToggleButton54.Value = True
If ToggleButton55.Value = False Then ToggleButton55.Value = True
If ToggleButton56.Value = False Then ToggleButton56.Value = True
If ToggleButton57.Value = False Then ToggleButton57.Value = True
End Sub

Private Sub TextBox1_Change()
Dim cell As Range
For Each cell In Worksheets("userformdata").Range("D2:D31")
If cell.Value = True Then cell.Offset(, 1).Value = TextBox1.Value
Next cell
End Sub

Private Sub TextBox2_Change()
Dim cell As Range
For Each cell In Worksheets("userformdata").Range("D2:D31")
If cell.Value = True Then cell.Offset(, 2).Value = TextBox2.Value
Next cell
End Sub

' Togglebuttons controls

Private Sub ToggleButton1_click()
If ToggleButton1.Value = True Then ToggleButton2.Value = True
If ToggleButton1.Value = True Then Worksheets("userformdata").Range("a2").Value = True
If ToggleButton1.Value = False Then Worksheets("userformdata").Range("a2").Value = False
End Sub

Private Sub ToggleButton2_click()
If ToggleButton2.Value = True Then Worksheets("userformdata").Range("a3").Value = True
If ToggleButton2.Value = False Then Worksheets("userformdata").Range("a3").Value = False
End Sub

Private Sub ToggleButton3_click()
If ToggleButton3.Value = True Then ToggleButton4.Value = True
If ToggleButton3.Value = True Then Worksheets("userformdata").Range("a4").Value = True
If ToggleButton3.Value = False Then Worksheets("userformdata").Range("a4").Value = False
End Sub

Private Sub ToggleButton4_click()
If ToggleButton4.Value = True Then Worksheets("userformdata").Range("a5").Value = True
If ToggleButton4.Value = False Then Worksheets("userformdata").Range("a5").Value = False
End Sub

Private Sub ToggleButton20_click()
If ToggleButton20.Value = True Then Worksheets("userformdata").Range("a21").Value = True
If ToggleButton20.Value = False Then Worksheets("userformdata").Range("a21").Value = False
End Sub

Private Sub ToggleButton21_click()
If ToggleButton21.Value = True Then ToggleButton22.Value = True
If ToggleButton21.Value = True Then Worksheets("userformdata").Range("a22").Value = True
If ToggleButton21.Value = False Then Worksheets("userformdata").Range("a22").Value = False
End Sub

Private Sub ToggleButton22_click()
If ToggleButton22.Value = True Then Worksheets("userformdata").Range("a23").Value = True
If ToggleButton22.Value = False Then Worksheets("userformdata").Range("a23").Value = False
End Sub

Private Sub ToggleButton23_click()
If ToggleButton23.Value = True Then ToggleButton24.Value = True
If ToggleButton23.Value = True Then Worksheets("userformdata").Range("a24").Value = True
If ToggleButton23.Value = False Then Worksheets("userformdata").Range("a24").Value = False
End Sub

Private Sub ToggleButton24_click()
If ToggleButton24.Value = True Then Worksheets("userformdata").Range("a25").Value = True
If ToggleButton24.Value = False Then Worksheets("userformdata").Range("a25").Value = False
End Sub

Private Sub ToggleButton25_click()
If ToggleButton25.Value = True Then ToggleButton26.Value = True
If ToggleButton25.Value = True Then Worksheets("userformdata").Range("a26").Value = True
If ToggleButton25.Value = False Then Worksheets("userformdata").Range("a26").Value = False
End Sub

Private Sub ToggleButton26_click()
If ToggleButton26.Value = True Then Worksheets("userformdata").Range("a27").Value = True
If ToggleButton26.Value = False Then Worksheets("userformdata").Range("a27").Value = False
End Sub

Private Sub ToggleButton27_click()
If ToggleButton27.Value = True Then ToggleButton28.Value = True
If ToggleButton27.Value = True Then Worksheets("userformdata").Range("a28").Value = True
If ToggleButton27.Value = False Then Worksheets("userformdata").Range("a28").Value = False
End Sub

Private Sub ToggleButton28_click()
If ToggleButton28.Value = True Then Worksheets("userformdata").Range("a29").Value = True
If ToggleButton28.Value = False Then Worksheets("userformdata").Range("a29").Value = False
End Sub

Private Sub ToggleButton29_click()
If ToggleButton29.Value = True Then ToggleButton30.Value = True
If ToggleButton29.Value = True Then Worksheets("userformdata").Range("a30").Value = True
If ToggleButton29.Value = False Then Worksheets("userformdata").Range("a30").Value = False
End Sub

Private Sub ToggleButton30_click()
If ToggleButton30.Value = True Then Worksheets("userformdata").Range("a31").Value = True
If ToggleButton30.Value = False Then Worksheets("userformdata").Range("a31").Value = False
End Sub[/PHP]

publicado

Sin el archivo, esto es lo máximo que se puede hacer:

Tampoco he podido probar las modificaciones por el mismo motivo.


Private Sub CommandButton11_Click()
For x = 1 To 57
Controls("ToggleButton" & x).Value = False
Next
End Sub


Private Sub CommandButton11_Click()
For x = 46 To 57
Controls("ToggleButton" & x).Value = False
Next
End Sub


Private Sub TextBox1_Change()
Dim cell As Range
For Each cell In Worksheets("userformdata").Range("D2:D31")
If cell.Value = True Then cell.Offset(, 1).Value = TextBox1.Value
Next cell
End Sub


Private Sub TextBox2_Change()
Dim cell As Range
For Each cell In Worksheets("userformdata").Range("D2:D31")
If cell.Value = True Then cell.Offset(, 2).Value = TextBox2.Value
Next cell
End Sub

Private Sub ToggleButton1_click(): ComúnToggleButton 1: End Sub
Private Sub ToggleButton2_click(): ComúnToggleButton 2: End Sub
Private Sub ToggleButton3_click(): ComúnToggleButton 3: End Sub
Private Sub ToggleButton4_click(): ComúnToggleButton 4: End Sub
Private Sub ToggleButton20_click(): ComúnToggleButton 20: End Sub
Private Sub ToggleButton21_click(): ComúnToggleButton 21: End Sub
Private Sub ToggleButton22_click(): ComúnToggleButton 22: End Sub
Private Sub ToggleButton23_click(): ComúnToggleButton 23: End Sub
Private Sub ToggleButton24_click(): ComúnToggleButton 24: End Sub
Private Sub ToggleButton35_click(): ComúnToggleButton 25: End Sub
Private Sub ToggleButton26_click(): ComúnToggleButton 26: End Sub
Private Sub ToggleButton27_click(): ComúnToggleButton 27: End Sub
Private Sub ToggleButton28_click(): ComúnToggleButton 28: End Sub
Private Sub ToggleButton29_click(): ComúnToggleButton 29: End Sub
Private Sub ToggleButton30_click(): ComúnToggleButton 30: End Sub


Private Sub ComúnToggleButton(Número As Integer)
If Controls("ToggleButton" & Número) = True Then Controls("ToggleButton" & Número + 1) = True
Worksheets("userformdata").Range("A" & Número + 1) = Controls("ToggleButton" & Número)
End Sub
[/CODE]

Archivado

Este tema está ahora archivado y está cerrado a más respuestas.

×
×
  • Crear nuevo...

Información importante

Echa un vistazo a nuestra política de cookies para ayudarte a tener una mejor experiencia de navegación. Puedes ajustar aquí la configuración. Pulsa el botón Aceptar, si estás de acuerdo.