简体   繁体   中英

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.

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. And also wks is properly assigned worksheet object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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