我正在尝试通过VBA宏删除多个列。我有一个在大部分情况下都有效的代码,但是当我到达第5行(或者可能发生在第4行和第5行之间)时,它会选择当前列右侧的所有列,并删除它们,而不是删除我选择的单个列。
ActiveWorkbook.ActiveeSheet.Rows(1).Find("location", lookat:=xlWhole).Select
ActiveCell.Offset(0, 0).Seleect
ActiveCell.EntireColumn.Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Delete例如,我想删除名为Location的列。但是,当我到达第4-5行时,它选择Location和Location右侧的所有列,然后第5行删除它们。
发布于 2020-07-29 13:03:43
试试这个:
Dim f As Range
Set f = ActiveSheet.Rows(1).Find("location", lookat:=xlWhole)
If Not f Is Nothing then f.EntireColumn.Delete尽管宏录制器倾向于这样编写代码,但您很少需要在VBA中选择/激活某些内容
https://stackoverflow.com/questions/63146446
复制相似问题