ExcelTonnie
Gebruiker
- Lid geworden
- 5 jul 2016
- Berichten
- 308
Om data te wijzigen in een tabel heb ik 4 onderdelen.
Aan de hand van een uniek nummer wordt een regel uit een tabel geselecteerd die ik kan wijzigen.
TxtST1 - t/m TxtST35
TxtLength1 - t/m TxtLength35
TxtCap1 - t/m TxtCap1 35
TxtCaps2 - t/m TxtCa2 35
Nu kan ik deze code 35x invoeren maar ga ervan uit dat dit een stuk eenvoudiger en korter kan.
Heb er 12 ingezet en is al een hele bups.
Hoe kan ik hetzelfde bereiken met minder code.
Aan de hand van een uniek nummer wordt een regel uit een tabel geselecteerd die ik kan wijzigen.
TxtST1 - t/m TxtST35
TxtLength1 - t/m TxtLength35
TxtCap1 - t/m TxtCap1 35
TxtCaps2 - t/m TxtCa2 35
Nu kan ik deze code 35x invoeren maar ga ervan uit dat dit een stuk eenvoudiger en korter kan.
Heb er 12 ingezet en is al een hele bups.
Hoe kan ik hetzelfde bereiken met minder code.
Code:
Private Sub DataWijzigen_Click()
Dim lastrow
Dim X As String
lastrow = ws1.Range("A" & Rows.Count).End(xlUp).Row
X = TxtSSCCzoek.Text 'dit is het zoek invoerveld
For currentrow = 1 To lastrow
If Cells(currentrow, 7).Text = X Then '7e kolom is waar de SSCC staan
ws1.Cells(currentrow, 8).Value = TxtST1.Text
ws1.Cells(currentrow, 9).Value = TxtLength1.Text
ws1.Cells(currentrow, 10).Value = Txt1Cap1.Text
ws1.Cells(currentrow, 11).Value = Txt2Cap1.Text
ws1.Cells(currentrow, 13).Value = TxtST2.Text
ws1.Cells(currentrow, 14).Value = TxtLength2.Text
ws1.Cells(currentrow, 15).Value = Txt1Cap2.Text
ws1.Cells(currentrow, 16).Value = Txt2Cap2.Text
ws1.Cells(currentrow, 18).Value = TxtST3.Text
ws1.Cells(currentrow, 19).Value = TxtLength3.Text
ws1.Cells(currentrow, 20).Value = Txt1Cap3.Text
ws1.Cells(currentrow, 21).Value = Txt2Cap3.Text
ws1.Cells(currentrow, 23).Value = TxtST4.Text
ws1.Cells(currentrow, 24).Value = TxtLength4.Text
ws1.Cells(currentrow, 25).Value = Txt1Cap4.Text
ws1.Cells(currentrow, 26).Value = Txt2Cap4.Text
ws1.Cells(currentrow, 28).Value = TxtST5.Text
ws1.Cells(currentrow, 29).Value = TxtLength5.Text
ws1.Cells(currentrow, 30).Value = Txt1Cap5.Text
ws1.Cells(currentrow, 31).Value = Txt2Cap5.Text
ws1.Cells(currentrow, 33).Value = TxtST6.Text
ws1.Cells(currentrow, 34).Value = TxtLength6.Text
ws1.Cells(currentrow, 35).Value = Txt1Cap6.Text
ws1.Cells(currentrow, 36).Value = Txt2Cap6.Text
ws1.Cells(currentrow, 38).Value = TxtST7.Text
ws1.Cells(currentrow, 39).Value = TxtLength7.Text
ws1.Cells(currentrow, 40).Value = Txt1Cap7.Text
ws1.Cells(currentrow, 41).Value = Txt2Cap7.Text
ws1.Cells(currentrow, 43).Value = TxtST8.Text
ws1.Cells(currentrow, 44).Value = TxtLength8.Text
ws1.Cells(currentrow, 45).Value = Txt1Cap8.Text
ws1.Cells(currentrow, 46).Value = Txt2Cap8.Text
ws1.Cells(currentrow, 58).Value = TxtST9.Text
ws1.Cells(currentrow, 59).Value = TxtLength9.Text
ws1.Cells(currentrow, 60).Value = Txt1Cap9.Text
ws1.Cells(currentrow, 61).Value = Txt2Cap9.Text
ws1.Cells(currentrow, 63).Value = TxtST10.Text
ws1.Cells(currentrow, 64).Value = TxtLength10.Text
ws1.Cells(currentrow, 65).Value = Txt1Cap10.Text
ws1.Cells(currentrow, 66).Value = Txt2Cap10.Text
ws1.Cells(currentrow, 68).Value = TxtST11.Text
ws1.Cells(currentrow, 69).Value = TxtLength11.Text
ws1.Cells(currentrow, 70).Value = Txt1Cap11.Text
ws1.Cells(currentrow, 71).Value = Txt2Cap11.Text
ws1.Cells(currentrow, 73).Value = TxtST12.Text
ws1.Cells(currentrow, 74).Value = TxtLength12.Text
ws1.Cells(currentrow, 75).Value = Txt1Cap12.Text
ws1.Cells(currentrow, 76).Value = Txt2Cap12.Text
End If
Next currentrow
TxtSSCCzoek.SetFocus
End Sub