简体   繁体   English

从特定行开始删除不需要的列-Excel VBA

[英]Deleting unwanted columns starting at a specific row - excel vba

For some reason I can't figure out how to do this... it seems so basic: 由于某种原因,我不知道该怎么做...似乎很基本:

Trying to delete unwanted columns starting at a specific row. 尝试删除从特定行开始的不需要的列。

Example: Want to delete Columns C, D, E, M, N and L all starting at row 10 of Wsh2. 示例:要删除所有从Wsh2的第10行开始的C,D,E,M,N和L列。

'deleting columns that are unwanted
Cells(wsh2.Cells("C10"), wsh2.Cells("C10").End(xlDown)).EntireColumn.Delete
Cells(wsh2.Cells("D10"), wsh2.Cells("C10").End(xlDown)).EntireColumn.Delete
Cells(wsh2.Cells("E10"), wsh2.Cells("C10").End(xlDown)).EntireColumn.Delete
Cells(wsh2.Cells("M10"), wsh2.Cells("C10").End(xlDown)).EntireColumn.Delete
Cells(wsh2.Cells("N10"), wsh2.Cells("C10").End(xlDown)).EntireColumn.Delete
Cells(wsh2.Cells("L10"), wsh2.Cells("C10").End(xlDown)).EntireColumn.Delete
End Sub

I've adapted a previous code that I found on here that used Range. 我已经改编了以前在这里找到的使用Range的代码。 I've also attempted using Union and Range but cant seem to figure it out. 我也曾尝试使用Union和Range,但似乎无法弄清楚。

Basically: Trying to delete only specific columns starting at a particular row after I've copied a range of rows from a previous worksheet. 基本上:在从上一个工作表中复制了一定范围的行之后,尝试仅删除从特定行开始的特定列。

Any help would be great. 任何帮助都会很棒。 Thank you! 谢谢!

如果使用EntireColumn.Delete它将删除整个列,则需要获取范围并将其删除,例如。

Range("C10:C" & Rows.Count).Delete

You do not actually want to delete the entire column, as you stated. 如您所说,您实际上并不想删除整个列。 You want to clear cells C10:Cend , D10:Dend , E10:Eend , M10:Mend , N10:Nend , and L10:Lend . 您要清除单元格C10:CendD10:DendE10:EendM10:MendN10:NendL10:Lend This is what you want to have your code do. 这就是您想要的代码。 Navigate to the cell of choice, and clear all cells below that specific coordinate. 导航到所选的单元格,然后清除该特定坐标以下的所有单元格。

For ease, you could just loop through all cells from C10 to C10000 and delete the contents of each cell, for example, which would be very simple to implement, though potentially not the most efficient. 为简单起见,您可以循环浏览从C10C10000所有单元,并删除每个单元的内容,例如,这可能非常容易实现,尽管可能不是最有效的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM