mardi 24 mars 2015

Excel VBA UserForm - Update/Override Data

I'm trying to pull and update some records thru an UserForm and I've almost got it, except for the piece of code that isn't working as intended. It's supposed to override the previous record (whatever information is found in the same row as the record found by the IDNum.


For some reason, it starts to copy the data as of column B when it should override everything as of Column A.


Here's the code.



Private Sub RecordUpdate_Click()
Dim LastRow As Long
Dim IDNum As String
Dim rngIDNum As Range
Dim WriteRow As Long
Dim ws As Worksheet

Set ws = Worksheets("Records")

With ActiveSheet

LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

Set rngIDNum = .Range("E1:E" & LastRow)

IDNum = txtID.Value

WriteRow = Application.Match(IDNum, rngIDNum, 0)

Cells(WriteRow, 1).Select

With ActiveCell

.Offset(0, 1).Value = txtName.Value
.Offset(0, 2).Value = txtlName.Value
.Offset(0, 3).Value = txtGender.Value
.Offset(0, 4).Value = txtAge.Value
.Offset(0, 5).Value = txtID.Value

End With

End With

End Sub


It leaves intact whatever is in column A and copies the edited entries from B to F instead of A to E.


Any inputs are greatly appreciated.


Aucun commentaire:

Enregistrer un commentaire