Excel columns delete  
Author Message
VBE_programmer





PostPosted: Visual Basic Express Edition, Excel columns delete Top

hi,

I want to delete some columns in Excel sheet.

I am using the following syntax.

all the columns are deleted but P3:P15 column not deleted.

the P3:P15 values coming to L3:L15 place.and it is not deleted

oSht.Range("L3:L15").EntireColumn.Delete()

oSht.Range("O3:O15").EntireColumn.Delete()

oSht.Range("P3:P15").EntireColumn.Delete()

oSht.Range("N3:N15").EntireColumn.Delete()

oSht.Range("M3:M15").EntireColumn.Delete()

what's wrong with this excel

Any help

Thanks




Visual Studio Express Editions44  
 
 
DTHMTLGOD





PostPosted: Visual Basic Express Edition, Excel columns delete Top

It looks like when you are deleting a column, it shifts everything over to the left one column, so you might be deleting the same column over and over again. I would try setting up a loop to delete the current column 5 times.

For I = 1 to 5

oSht.Range("L3:L15").EntireColumn.Delete()

next


 
 
VBE_programmer





PostPosted: Visual Basic Express Edition, Excel columns delete Top

Brilliant DTHMTLGOD ,

Above code working perfectly.

Thanks