Deleting the columns which has no data using Vba

I'm trying to delete the columns with rowcount 1.I have written the code,But the problem is it checks for first two columns only,even though I have given the proper values in the for loop.Can anyone please help me to check this .please find the code below.

Dim col As Long
Dim row,lastRow1 As Long
Dim iCntr1 as integer


For iCntr1 = 1 To 15 ' for each column
    'Finding last Row of current Column
    With ActiveSheet
        lastRow1 = .Cells(.Rows.count, iCntr1).End(xlUp).row
    End With
    If lastRow1 = 1 Then
        Worksheets("Testdata").Columns(iCntr1).EntireColumn.Delete Shift:=xlToLeft
    End If

Thanks In advance.

Read more here:

Content Attribution

This content was originally published by Myna at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: