How to remove Excel VBA range columns

I have a range called “Start” located in cell “I21”. And I have another range called “End” located in cell “Q21”. I want to write code to remove all columns between them. In other words, I want to completely remove the columns J, K, L, M, N, O, P. 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 ... this gives me an error as an undefined application. please, help,

+3
source share
2 answers
Range(Range("start").Offset(,1), Range("end").Offset(,-1)).EntireColumn.Delete  
+7
source
    Dim xlsRange As Excel.Range

    xlsRange = xlsSheet.Range("i2", "i10")

    xlsRange.EntireColumn.Delete()
-1
source

Source: https://habr.com/ru/post/1762090/


All Articles