简体   繁体   English

删除Excel VBA中的列范围

[英]Delete the Range of Columns in Excel VBA

I am trying to delete the range of columns but getting error "Application Defined or object defined error". 我正在尝试删除列的范围,但出现错误“应用程序定义或对象定义的错误”。 In the below code wks is the worksheet and colStart and colEnd are variables with values. 在下面的代码中,wks是工作表,colStart和colEnd是具有值的变量。

Dim colDelete As String

colDelete = wks.Range(wks.Cells(1, colStart), wks.Cells(1, colEnd)).EntireColumn.Delete

Declare your variables. 声明变量。 Always. 总是。

dim colStart as long
dim colEnd as long
dim wks as Worksheet

It should work this way. 它应该以这种方式工作。

在此处输入图片说明

Yes vacip the colStart and colEnd has integer values as you can see in watch screen of my image. 是的,您可以在colStart和colEnd的整数值中查看图像的监视屏幕。 And also wks is properly assigned worksheet object. 并且wks正确分配了工作表对象。

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

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