嗨。我有一个表(Table1),其中的列名为Enq 1,Enq 2,依此类推。我需要做的是能够根据上方单元格的条件选择该列,然后删除其中的数据。我写了下面的代码,但我似乎无法弄清楚如何使用VBA选择列。我无法使用偏移,因为将来可能会添加更多行
Dim rng As Range: Set rng = ActiveSheet.Range("Removal")
Dim cel As Range
For Each cel In rng.Cells
If cel = "SELECTED FOR REMOVAL" Then
Range("Table1[Enq 2]").Select
Selection.ClearContents
End If
Next cel
谢谢
答案 0 :(得分:2)
最好在这里使用For..Next
循环来删除要删除的列:
Dim ws As Worksheet: Set ws = ThisWorkbook.ActiveSheet
Dim rng As Range: Set rng = ws.Range("Removal")
Dim i as Long
For i = 1 To rng.Columns.Count
If rng.Cells(1, i).Value = "SELECTED FOR REMOVAL" Then
ws.ListObjects("Table1").ListColumns(i).Range.ClearContents
End If
Next i
答案 1 :(得分:1)
或者,您可以尝试:
interface IUser {
name: string;
someMethod: string;
}
const models: { [key: string]: IUser } = {
Users: {
name: "Users",
someMethod: "xxx"
}
};