Question : Macro in excel not doing what i think the code asks?

I have recorded a macro in excel and adapted it to include some If furmulas

one part of the code is supossed to look up A1 and if empty then select entire column and delete.

I have tried the following formula in the following ways. All produce random results:

 Columns("B:B").Select
        If IsEmpty(B1) Then
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlToLeft
    End If

Or


        If IsEmpty(B1) Then
    Columns("B:B").Select
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlToLeft
    End If

Or  Columns("B:B").Select
        If (B1) = "" Then
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlToLeft
    End If



All of these you see the macro selecting the column and then on some colums it deletes if A1 etc has something in it and on others it does the oposite

Answer : Macro in excel not doing what i think the code asks?

And to delete the entire column for the first blank cell (within the usedrange) in row 1 you could try this - if the cell is truly blank

Cheers

Dave
1:
2:
3:
4:
5:
6:
Sub KillA()
Dim rng1 As Range
On Error Resume Next
Set rng1 = Rows(1).SpecialCells(xlBlanks)
If Not rng1 Is Nothing Then rng1.Cells(1).EntireColumn.Delete
End Sub
Random Solutions  
 
programming4us programming4us