[英]I need to delete a row from an array if one of the array elements is equal to a value. Using Excel VBA
I have copied an Excel table to an array.我已将 Excel 表复制到数组中。
Sub
Dim Mentors As Variant
Mentors = Worksheets("Mentors").ListObjects("Mentors").DataBodyRange.Value
end sub
Now I would like to loop through the Mentors array to find rows with invalid values and delete those rows from the array, but I don't know how to do that.现在我想遍历 Mentors 数组以查找具有无效值的行并从数组中删除这些行,但我不知道该怎么做。
Then I will put the array back in the table.然后我将数组放回表中。 (That I know how to do).
(我知道该怎么做)。
Deleting a row from an array is a pain, it would be easier to work directly on your table:从数组中删除一行很痛苦,直接在你的表上工作会更容易:
Dim tbl As ListObject
Dim x As Long
Set tbl = ActiveSheet.ListObjects("Mentors")
For x = tbl.ListRows.Count to 1 step -1
If your_delete_conditions_go_here Then
tbl.ListRows(x).Delete
End If
Next x
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.