Hi!
Can anyone please help me write a shorter vba code?
This vba code I need for editing futsal players records.
That vba code works well, but it's too long.
The code below is short example because its too long. But I have in league 10 teams, so I would like a better solution.
Thank you in advance for your help.
Kind Regards
--Daniel
Can anyone please help me write a shorter vba code?
This vba code I need for editing futsal players records.
That vba code works well, but it's too long.
The code below is short example because its too long. But I have in league 10 teams, so I would like a better solution.
Thank you in advance for your help.
Kind Regards
--Daniel
Code:
<code>Private Sub OptionButton1_Click()
txtBox1.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("A2").Value
txtBox2.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("B2").Value
txtBox3.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("A3").Value
txtBox4.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("B3").Value
txtBox5.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("A4").Value
txtBox6.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("B4").Value
txtBox7.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("A5").Value
txtBox8.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("B5").Value
txtBox9.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("A6").Value
txtBox10.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("B6").Value
txtBox11.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("A7").Value
txtBox12.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("B7").Value
txtBox13.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("A8").Value
txtBox14.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("B8").Value
txtBox15.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("A9").Value
txtBox16.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("B9").Value
txtBox17.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("A10").Value
txtBox18.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("B10").Value
txtBox19.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("A11").Value
txtBox20.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("B11").Value
txtBox21.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("A12").Value
txtBox22.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("B12").Value
txtBox23.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("A13").Value
txtBox24.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("B13").Value
txtBox25.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("A14").Value
txtBox26.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("B14").Value
txtBox27.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("A15").Value
txtBox28.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("B15").Value
txtBox29.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("A16").Value
txtBox30.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("B16").Value
txtBox31.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("A17").Value
txtBox32.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("B17").Value
txtBox33.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("A18").Value
txtBox34.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("B18").Value
txtBox35.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("A19").Value
txtBox36.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("B19").Value
txtBox37.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("A20").Value
txtBox38.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("B20").Value
txtBox39.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("A21").Value
txtBox40.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("B21").Value
txtBox41.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("A22").Value
txtBox42.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("B22").Value
txtBox43.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("A23").Value
txtBox44.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("B23").Value
txtBox45.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("A24").Value
txtBox46.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("B24").Value
txtBox47.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("A25").Value
txtBox48.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("B25").Value
txtBox49.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("A26").Value
txtBox50.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("B26").Value
End Sub
Private Sub OptionButton2_Click()
txtBox1.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("C2").Value
txtBox2.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("D2").Value
txtBox3.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("C3").Value
txtBox4.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("D3").Value
txtBox5.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("C4").Value
txtBox6.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("D4").Value
txtBox7.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("C5").Value
txtBox8.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("D5").Value
txtBox9.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("C6").Value
txtBox10.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("D6").Value
txtBox11.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("C7").Value
txtBox12.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("D7").Value
txtBox13.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("C8").Value
txtBox14.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("D8").Value
txtBox15.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("C9").Value
txtBox16.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("D9").Value
txtBox17.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("C10").Value
txtBox18.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("D10").Value
txtBox19.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("C11").Value
txtBox20.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("D11").Value
txtBox21.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("C12").Value
txtBox22.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("D12").Value
txtBox23.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("C13").Value
txtBox24.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("D13").Value
txtBox25.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("C14").Value
txtBox26.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("D14").Value
txtBox27.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("C15").Value
txtBox28.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("D15").Value
txtBox29.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("C16").Value
txtBox30.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("D16").Value
txtBox31.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("C17").Value
txtBox32.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("D17").Value
txtBox33.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("C18").Value
txtBox34.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("D18").Value
txtBox35.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("C19").Value
txtBox36.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("D19").Value
txtBox37.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("C20").Value
txtBox38.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("D20").Value
txtBox39.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("C21").Value
txtBox40.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("D21").Value
txtBox41.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("C22").Value
txtBox42.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("D22").Value
txtBox43.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("C23").Value
txtBox44.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("D23").Value
txtBox45.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("C24").Value
txtBox46.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("D24").Value
txtBox47.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("C25").Value
txtBox48.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("D25").Value
txtBox49.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("C26").Value
txtBox50.Text = ThisWorkbook.Sheets("soupisky_tymu").Range("D26").Value
End Sub
Private Sub CommandButton1_Click()
txtBox2.Text = Format(txtBox2, "dd.mm.yyyy")
txtBox4.Text = Format(txtBox4, "dd.mm.yyyy")
txtBox6.Text = Format(txtBox6, "dd.mm.yyyy")
txtBox8.Text = Format(txtBox8, "dd.mm.yyyy")
txtBox10.Text = Format(txtBox10, "dd.mm.yyyy")
txtBox12.Text = Format(txtBox12, "dd.mm.yyyy")
txtBox14.Text = Format(txtBox14, "dd.mm.yyyy")
txtBox16.Text = Format(txtBox16, "dd.mm.yyyy")
txtBox18.Text = Format(txtBox18, "dd.mm.yyyy")
txtBox20.Text = Format(txtBox20, "dd.mm.yyyy")
txtBox22.Text = Format(txtBox22, "dd.mm.yyyy")
txtBox24.Text = Format(txtBox24, "dd.mm.yyyy")
txtBox26.Text = Format(txtBox26, "dd.mm.yyyy")
txtBox28.Text = Format(txtBox28, "dd.mm.yyyy")
txtBox30.Text = Format(txtBox30, "dd.mm.yyyy")
txtBox32.Text = Format(txtBox32, "dd.mm.yyyy")
txtBox34.Text = Format(txtBox34, "dd.mm.yyyy")
txtBox36.Text = Format(txtBox36, "dd.mm.yyyy")
txtBox38.Text = Format(txtBox38, "dd.mm.yyyy")
txtBox40.Text = Format(txtBox40, "dd.mm.yyyy")
txtBox42.Text = Format(txtBox42, "dd.mm.yyyy")
txtBox44.Text = Format(txtBox44, "dd.mm.yyyy")
txtBox46.Text = Format(txtBox46, "dd.mm.yyyy")
txtBox48.Text = Format(txtBox48, "dd.mm.yyyy")
txtBox50.Text = Format(txtBox50, "dd.mm.yyyy")
If OptionButton1 = True Then
ThisWorkbook.Sheets("soupisky_tymu").Range("A2:B26").ClearContents
ThisWorkbook.Sheets("soupisky_tymu").Range("A2").Value = txtBox1.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("B2").Value = txtBox2.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("A3").Value = txtBox3.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("B3").Value = txtBox4.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("A4").Value = txtBox5.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("B4").Value = txtBox6.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("A5").Value = txtBox7.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("B5").Value = txtBox8.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("A6").Value = txtBox9.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("B6").Value = txtBox10.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("A7").Value = txtBox11.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("B7").Value = txtBox12.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("A8").Value = txtBox13.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("B8").Value = txtBox14.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("A9").Value = txtBox15.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("B9").Value = txtBox16.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("A10").Value = txtBox17.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("B10").Value = txtBox18.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("A11").Value = txtBox19.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("B11").Value = txtBox20.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("A12").Value = txtBox21.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("B12").Value = txtBox22.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("A13").Value = txtBox23.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("B13").Value = txtBox24.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("A14").Value = txtBox25.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("B14").Value = txtBox26.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("A15").Value = txtBox27.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("B15").Value = txtBox28.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("A16").Value = txtBox29.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("B16").Value = txtBox30.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("A17").Value = txtBox31.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("B17").Value = txtBox32.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("A18").Value = txtBox33.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("B18").Value = txtBox34.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("A19").Value = txtBox35.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("B19").Value = txtBox36.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("A20").Value = txtBox37.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("B20").Value = txtBox38.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("A21").Value = txtBox39.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("B21").Value = txtBox40.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("A22").Value = txtBox41.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("B22").Value = txtBox42.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("A23").Value = txtBox43.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("B23").Value = txtBox44.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("A24").Value = txtBox45.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("B24").Value = txtBox46.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("A25").Value = txtBox47.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("B25").Value = txtBox48.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("A26").Value = txtBox49.Text
ThisWorkbook.Sheets("soupisky_tymu").Range("B26").Value = txtBox50.Text
OptionButton1.Value = False
txtBox1.Text = ""
txtBox2.Text = ""
txtBox3.Text = ""
txtBox4.Text = ""
txtBox5.Text = ""
txtBox6.Text = ""
txtBox7.Text = ""
txtBox8.Text = ""
txtBox9.Text = ""
txtBox10.Text = ""
txtBox11.Text = ""
txtBox12.Text = ""
txtBox13.Text = ""
txtBox14.Text = ""
txtBox15.Text = ""
txtBox16.Text = ""
txtBox17.Text = ""
txtBox18.Text = ""
txtBox19.Text = ""
txtBox20.Text = ""
txtBox21.Text = ""
txtBox22.Text = ""
txtBox23.Text = ""
txtBox24.Text = ""
txtBox25.Text = ""
txtBox26.Text = ""
txtBox27.Text = ""
txtBox28.Text = ""
txtBox29.Text = ""
txtBox30.Text = ""
txtBox31.Text = ""
txtBox32.Text = ""
txtBox33.Text = ""
txtBox34.Text = ""
txtBox35.Text = ""
txtBox36.Text = ""
txtBox37.Text = ""
txtBox38.Text = ""
txtBox39.Text = ""
txtBox40.Text = ""
txtBox41.Text = ""
txtBox42.Text = ""
txtBox43.Text = ""
txtBox44.Text = ""
txtBox45.Text = ""
txtBox46.Text = ""
txtBox47.Text = ""
txtBox48.Text = ""
txtBox49.Text = ""
txtBox50.Text = ""
End If
End Sub
Private Sub CommandButton2_Click()
Unload UserForm3
End Sub</code>