I tried your suggestion, but the range is still
not refreshed after I deleted the row. Do you have any ideas? Here are
my codes for the subroutine called RangeSelection() and my form.
'Range Selection
Sub RangeSelection()
Worksheets("EnterCowData").Activate
CmyLastRow = LastCell(Worksheets("EnterCowData")).Address
CmyRange = "A3:" & CmyLastRow
'sort the range by CowID
range(CmyRange).Select
Selection.Sort Key1:=range("A3"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom,
_
DataOption1:=xlSortNormal
Worksheets("EnterCowData").range(CmyRange).Name = "Options"
End Sub
Private Sub UserForm_initialize()
Call RangeSelection
cboCowList.RowSource = "Options"
cboCowList.BoundColumn = 1
cboCowList.ColumnCount = 1
Application.ScreenUpdating = True
End Sub
Private Sub cboCowList_Click()
Worksheets("EnterCowData").Activate
CmyLastRow = LastCell(Worksheets("EnterCowData")). Row My problem
is here after I deleted a specific row.
CmyRange = "A3: A" & CmyLastRow
Set CowListStart = Worksheets("EnterCowData").range("A3")
CowID = cboCowList.Value
i = 0
Do Until i = CmyLastRow + 1
If CowListStart.Offset(i, 0).Value = CowID Then
DeleteRange = "A" & CowListStart.Offset(i, 0).Row
End If
i = i + 1
Loop
End Sub
Private Sub cmdProblemDelete_Click()
message = "Are you sure you want to delete cow " & CowID & "?"
If MsgBox(message, vbQuestion + vbYesNo, _
"Confirm Delete") = vbYes Then
' Delete current row:
Worksheets("EnterCowData").Activate
range(DeleteRange).EntireRow.Delete
'reset the range
Call RangeSelection
End If
End Sub