Delete Entire Column

K

K

Hi all, I am trying to delete EntireColumn of Range("I9:BF9") where
cell value in that range is "X". I tried doing it with below code but
I its not deleting all the columns. I think I might need to put
something where it say "i" in line "If Cells(9, i).Value = "X" Then"
and "Cells(9, i).EntireColumn.Delete". But I cant work it out. Please
can any friend can help me on this

Code I am using************

Sub DelCol()
For i = Range("I9:BF9").Columns.Count To 1 Step -1
If Cells(9, i).Value = "X" Then
Cells(9, i).EntireColumn.Delete
End If
Next
End Sub
 
R

Roger Govier

Hi K

Try
Sub DelCol()
Dim i As Long
For i = Range("I9:BF9").Columns.Count + 8 To 9 Step -1
If Cells(9, i).Value = "X" Then
Columns(i).EntireColumn.Delete
End If
Next
End Sub

You need to add 8 (columns(A:G)) to your Count and to your final value to
ensure it is the correct columns you are deleting
--

Regards
Roger Govier

K said:
Hi all, I am trying to delete EntireColumn of Range("I9:BF9") where
cell value in that range is "X". I tried doing it with below code but
I its not deleting all the columns. I think I might need to put
something where it say "i" in line "If Cells(9, i).Value = "X" Then"
and "Cells(9, i).EntireColumn.Delete". But I cant work it out. Please
can any friend can help me on this

Code I am using************

Sub DelCol()
For i = Range("I9:BF9").Columns.Count To 1 Step -1
If Cells(9, i).Value = "X" Then
Cells(9, i).EntireColumn.Delete
End If
Next
End Sub

__________ Information from ESET Smart Security, version of virus
signature database 5641 (20101123) __________

The message was checked by ESET Smart Security.

http://www.eset.com

__________ Information from ESET Smart Security, version of virus signature database 5641 (20101123) __________

The message was checked by ESET Smart Security.

http://www.eset.com
 
K

K

Hi K

Try
Sub DelCol()
    Dim i As Long
    For i = Range("I9:BF9").Columns.Count + 8 To 9 Step -1
        If Cells(9, i).Value = "X" Then
            Columns(i).EntireColumn.Delete
        End If
    Next
End Sub

You need to add 8 (columns(A:G)) to your Count and to your final value to
ensure it is the correct columns you are deleting
--

Regards
Roger Govier













__________ Information from ESET Smart Security, version of virus signature database 5641 (20101123) __________

The message was checked by ESET Smart Security.

http://www.eset.com- Hide quoted text -

- Show quoted text -

thanks lot Roger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top