我有一个带有2个文本框的窗体。我正在使用随机化方法根据D列选取某个国家/地区。我希望能够在选定国家/地区后移除所选国家/地区。在我的屏幕截图中,我们会注意到尼日利亚已被分配给Jessie。如何从列表中删除数据已被选中
这里ClickMe
Private Sub CommandButton1_Click()
Dim randomCtry As Long
Randomize
Application.Wait Now + TimeValue("00:00:01")
DoEvents
Dim LastRow As Long
LastRow = Sheets("Sheet1").Range("D" & Rows.Count).End(xlUp).Row
'With txtDestination
' .Text = Sheets("Sheet1").Range("D" & Int((LastRow - 1) * Rnd + 2))
'
'End With
Set randomCtry = Sheets("Sheet1").Range("D" & Int((LastRow - 1) * Rnd + 2))
txtDestination.Text = randomCtry.Text
randomCtry.Delete Shift:=xlUp ' <-- remove the selected country from the list
Application.Wait Now + TimeValue("00:00:01")
DoEvents
With Sheet1
With .Range("A" & .Rows.Count).End(xlUp)
.Offset(1).Resize(1, 2).Value = Array(txtMilitary.Text, txtDestination.Text)
End With
On Error Resume Next
End With
End Sub
是否要永久删除列D中所选国家/地区的列表? –
不是真的删除。我真正想要的是,一旦这支军队回归,那么这个国家将重新回到名单中。就是这样。 –