0

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
1
  • This code works for me. Are you sure wks is a properly assigned worksheet object, and colStart and colEnd are >0 whole numbers? Are you sure the worksheet is not protected? Can you post some more of your code? Commented Jun 17, 2015 at 15:14

2 Answers 2

2

Declare your variables. Always.

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

It should work this way.

Sign up to request clarification or add additional context in comments.

Comments

0

enter image description here

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.

4 Comments

Well, they are actually strings, not numbers. I'll post an answer, but you need to declare your variables.
Actually I have declared my variables in my code. The code is too long so not able to paste the whole code here.
Ok, so why does it say Type: "string" in your watches window?
Thanks Vacip. I got my mistake. My variables are string. My bad. Thanks a lot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.