immediate help please

P

programmer_int

i am now able to insert data in an excel spread sheet using a user for
thanks to Tom Ogilvy, but i also need to update and delete dat
sometimes from the excel spreadsheet using user forms....for example
want to update or delete a row where employee id=100

please help me, i need to solve this problem immedaitel
 
T

Tom Ogilvy

Assume you have a combobox that lists employee ID's (combobox1) and a
button named cmd_DeleteChoice that when pushed, you want to delete the
employee-id selected in combobox1.

Assume Empoyee data is in a sheet named DATA and the employee ID's start in
A2 with contiguous entries to the last employee.

Private Sub Userform_Initialize()
Dim rng as Range
With Worksheets("Data")
set rng = .Range(.Cells(2,1),.Cells(2,1).End(xldown))
end with
Combobox1.List = rng
End Sub

Private Sub Cmd_DeleteChoice()
Dim rng as Range
With Worksheets("Data")
set rng = .Range(.Cells(2,1),.Cells(2,1).End(xldown))
end with
if combobox1.ListIndex <> -1 then
rng(Combobox1.ListIndex+1).EntireRow.Delete
' now reset combobox1 list
With Worksheets("Data")
set rng = .Range(.Cells(2,1),.Cells(2,1).End(xldown))
end with
Combobox1.List = rng.Value
end If
End sub
 
Top