Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete columns of a range Excel VBA

Tags:

excel

vba

I have a range named "Start" located at cell "I21". And I have another range named "End" located at cell "Q21". I want to write a code to delete all the columns between them. In other words, I want to delete columns J,K,L,M,N,O,P completely. Here is the code I have:

with ThisWorkbook.sheets("Sheet1")
    'unprotect sheet
    .Columns(.Range("Start").Column+1 & ":" & .Range("End").Column-1).Select
     Selection.Delete Shift:xlLeft
End with 

when it comes to the first line .Columns... it gives me an error as undefined application. please help,

like image 614
guest1 Avatar asked Dec 20 '25 15:12

guest1


1 Answers

Range(Range("start").Offset(,1), Range("end").Offset(,-1)).EntireColumn.Delete  
like image 169
shahkalpesh Avatar answered Dec 23 '25 16:12

shahkalpesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!