0

I wanted to update a record from my listbox.

Record shows in ListBox(lstDisplay),when I clicked on a single record, those record will display in the textfield, where I can start to edit them.

And then I have to click Save to save the changes,however I'm getting an error.

Please see my code.

Please see screenshot screenshot

Private Sub cmdSave_Click()
Dim i As Integer
For i = 0 To Range("A65356").End(xlUp).Row - 1
If lstDisplay.Selected(i) Then
    Rows(i + 1).Select

 Sheet.Cells(i, 1) = txtSearch.Text
 Sheet.Cells(i, 2) = txtLname.Text
 Sheet.Cells(i, 3) = txtFname.Text
 Sheet.Cells(i, 4) = txtCourse.Value
 Sheet.Cells(i, 5) = txtYear.Value




End If

Next i
End Sub
Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
  • 1
    `Sheet` means nothing without actually referring to a worksheet. You could refer to [its index, name, or code name](https://riptutorial.com/excel-vba/example/11272/worksheet--name---index-or--codename). Next to that, specify a wb & ws for your ranges and [avoid using Select](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba) – Tim Stack Apr 29 '19 at 12:42
  • Hello and walcome on SO. Besides knowing that you get an error (if everything was fine you probably wouldn't ne here) it would help us to know WHAT is the error you're getting? – Laurent S. Apr 29 '19 at 12:43
  • `For i = 0 to` never start from Zero as there would be no cells( 0, XXX) in excel. Also Make `Sheet.` to `Sheets("Sheet name")` where "Sheet name" is actual sheet name. – Ahmed AU Apr 29 '19 at 12:50
  • Unrelated, but should `A65356` instead be `A65536`, i.e. 2^16? – jsheeran Apr 29 '19 at 12:57
  • Maybe it's time to upgrade from Excel (e.g. to Access)... – Zack Apr 29 '19 at 13:35

0 Answers0