编辑/更新VBA中的现有行数据

时间:2019-05-16 16:08:21

标签: excel vba

我的记事本中有一些数据(ID,姓名,姓氏,生日等)。我有将数据提取到userform.textboxes的代码,但是如果我尝试对其进行编辑并按命令按钮,它将失败。 (错误13:键入不匹配

这是我的命令按钮代码,用于更改/更新现有数据:

Private Sub Wijzigen_Click()
Dim gegeven(1 To 10000) As personeel
Dim int_teller_n As Integer
Dim int_teller_m As Integer
Dim int_teller_p As Integer
Dim pad As String

pad = "C:\Users\fhaka\Downloads\Overzicht_Personeelsleden.txt"
int_teller_n = 1
int_teller_m = 1
int_teller_p = 1


Open pad For Input As #8

Do While Not (EOF(8))

Input #8, gegeven(int_teller_n).int_ID, gegeven(int_teller_n).str_Voornaam, gegeven(int_teller_n).str_Naam, gegeven(int_teller_n).int_Aantal_kinderen, gegeven(int_teller_n).str_Geboortedatum, gegeven(int_teller_n).str_Startdatum, gegeven(int_teller_n).str_Einddatum, gegeven(int_teller_n).str_Diploma, gegeven(int_teller_n).sng_Aantal_minuten_gewerkt, gegeven(int_teller_n).str_IN, gegeven(int_teller_n).str_UIT, gegeven(int_teller_n).str_Record


    gegeven(int_teller_n).str_IN = Now



int_teller_n = int_teller_n + 1

Loop
Close #8

Open pad For Output As #8

For int_teller_p = 1 To int_teller_n - 1
    Write #8, gegeven(int_teller_p).int_ID, gegeven(int_teller_p).str_Voornaam, gegeven(int_teller_p).str_Naam, gegeven(int_teller_p).int_Aantal_kinderen, gegeven(int_teller_p).str_Geboortedatum, gegeven(int_teller_p).str_Startdatum, gegeven(int_teller_p).str_Einddatum, gegeven(int_teller_p).str_Diploma, gegeven(int_teller_p).sng_Aantal_minuten_gewerkt, gegeven(int_teller_p).str_IN, gegeven(int_teller_p).str_UIT, gegeven(int_teller_p).str_Record
Next

Close #8

Dim int_ID As Integer
Dim str_Voornaam As String
Dim str_Naam As String
Dim int_Aantal_kinderen As Integer
Dim str_Geboortedatum As String
Dim str_Startdatum As String
Dim str_Einddatum As String
Dim str_Diploma As String
Dim sng_Aantal_minuten_gewerkt As Single
Dim str_IN As String
Dim str_UIT As String
Dim int_clear As Integer
int_pagina_grootte = 6

For int_clear = 3 To int_pagina_grootte
    Worksheets("Basisgegevens").Cells(int_clear, 1) = ""
    Worksheets("Basisgegevens").Cells(int_clear, 2) = ""
    Worksheets("Basisgegevens").Cells(int_clear, 3) = ""
    Worksheets("Basisgegevens").Cells(int_clear, 4) = ""
    Worksheets("Basisgegevens").Cells(int_clear, 5) = ""
    Worksheets("Basisgegevens").Cells(int_clear, 6) = ""
    Worksheets("Basisgegevens").Cells(int_clear, 7) = ""
    Worksheets("Basisgegevens").Cells(int_clear, 8) = ""
    Worksheets("Basisgegevens").Cells(int_clear, 9) = ""
    Worksheets("Basisgegevens").Cells(int_clear, 10) = ""
    Worksheets("Basisgegevens").Cells(int_clear, 11) = ""
Next

Open pad For Input As #4
Do Until (EOF(4))
Input #4, int_ID, str_Voornaam, str_Naam, int_Aantal_kinderen, str_Geboortedatum, str_Startdatum, str_Einddatum, str_Diploma, sng_Aantal_minuten_gewerkt, str_IN, str_UIT, str_EOR
If int_ID = CInt(UserForm_IN.TextBox1.Text) Then
    Worksheets("Basisgegevens").Cells(3, 1) = int_ID
    Worksheets("Basisgegevens").Cells(3, 2) = str_Voornaam
    Worksheets("Basisgegevens").Cells(3, 3) = str_Naam
    Worksheets("Basisgegevens").Cells(3, 4) = int_Aantal_kinderen
    Worksheets("Basisgegevens").Cells(3, 5) = str_Geboortedatum
    Worksheets("Basisgegevens").Cells(3, 6) = str_Startdatum
    Worksheets("Basisgegevens").Cells(3, 7) = str_Einddatum
    Worksheets("Basisgegevens").Cells(3, 8) = str_Diploma
    Worksheets("Basisgegevens").Cells(3, 9) = sng_Aantal_minuten_gewerkt
    Worksheets("Basisgegevens").Cells(3, 10) = str_IN
    Worksheets("Basisgegevens").Cells(3, 11) = str_UIT
End If
Loop
Close #4
Unload Me
End Sub

这是我的代码来提取所有现有数据:

Private Sub Getbutton_Click()
Dim id As Integer, i As Integer, j As Integer, flag As Boolean
If IsNumeric(UserForm_Wijzigen.TextBox1.Value) Then
    flag = False
    i = 0
    id = UserForm_Wijzigen.TextBox1.Value

    Do While Cells(i + 1, 1).Value <> ""

        If Cells(i + 1, 1).Value = id Then
            flag = True
            For j = 2 To 7
                UserForm_Wijzigen.Controls("TextBox" & j).Value = Cells(i + 1, j).Value
            Next j
        End If

        i = i + 1

    Loop

    If flag = False Then
        For j = 2 To 7
            UserForm_Wijzigen.Controls("TextBox" & j).Value = ""
        Next j
    End If

Else
    For j = 1 To 4
    UserForm_Wijzigen.Controls("TextBox" & j).Value = ""
    Next j
End If

End Sub

以下是我的工作表和用户表单的一些图片 Worksheet UserForm

我能够取出请求的数据,但是我不能替换/更新/编辑它。

我要对其进行编辑,它还应该更新我的记事本路径文件(每个人的数据都存储在该文件中)。

0 个答案:

没有答案