Hey all,
My question is, instead of deleting the row, how can I use the combobox to replace that row with the updated info rather than delete and resort?
I have a combobox that selects names from a sheet, column A and populates itself on Userform activate/initalize. Using the Combobox to select a name, this code below populates all the fields on the form, various text and comboboxs.
When users hits the update button, it currently finds the row and deletes it, see second code example, but this reaks havoc on various parts of the program, I have to move the combobox and add name textbox's because when it deletes the row, the combobox takes on the next rowsource and then writes that info, rather than the info selected.
Private Sub ComboBox1_Change()
If bBlockEvents = True Then Exit Sub
If ComboBox1.Value = "" Then
Reset
bBlockEvents = True
ComboBox1.ListIndex = -1
bBlockEvents = False
Exit Sub
End If
userow = ComboBox1.ListIndex + 3
usercolumn = 1
If userow = "0" Then
ComboBox1.Value = ""
Reset
Else
Special
TextBox1.Value = Worksheets("EPR Tracker").Cells(userow, usercolumn).Value
TextBox8.Value = Worksheets("EPR Tracker").Cells(userow, usercolumn + 1).Value
TextBox2.Value = Worksheets("EPR Tracker").Cells(userow, usercolumn + 2).Value
Me.TextBox2.Value = Format(Me.TextBox2.Value, "DD-MMM-YY")
TextBox3.Value = Worksheets("EPR Tracker").Cells(userow, usercolumn + 3).Value
Me.TextBox3.Value = Format(Me.TextBox3.Value, "DD-MMM-YY")
TextBox4.Value = Worksheets("EPR Tracker").Cells(userow, usercolumn + 4).Value
Me.TextBox4.Value = Format(Me.TextBox4.Value, "DD-MMM-YY")
TextBox5.Value = Worksheets("EPR Tracker").Cells(userow, usercolumn + 5).Value
Me.TextBox5.Value = Format(Me.TextBox5.Value, "DD-MMM-YY")
ComboBox2.Value = Worksheets("EPR Tracker").Cells(userow, usercolumn + 6).Value
TextBox6.Value = Worksheets("EPR Tracker").Cells(userow, usercolumn + 7).Value
Me.TextBox6.Value = Format(Me.TextBox6.Value, "DD-MMM-YY")
ComboBox4.Value = Worksheets("EPR Tracker").Cells(userow, usercolumn + 8).Value
TextBox7.Value = Worksheets("EPR Tracker").Cells(userow, usercolumn + 9).Value
Me.TextBox7.Value = Format(Me.TextBox7.Value, "DD-MMM-YY")
ComboBox3.Value = Worksheets("EPR Tracker").Cells(userow, usercolumn + 10).Value
End If
End Sub
Display More
This code is within a command button click sub.
' Stores the name for search value
NameOrig = TextBox1.Value
'Finds the name from the dropdown and deletes it
With Worksheets("EPR Tracker").Range("A:A")
Set c = .Find(NameOrig)
If c = c Then
c.EntireRow.Delete
End If
End With
Display More
Then below that, I add a line to the worksheet, dump in the info (which changed to the next row down because of the deleting the row) and then re-write it to that empy line, then resort.
I know there has to be an easier way.
Thanks in advance for any help!
Joe