Hi,
I am trying to make a simple macro, but I'm stuck and need some advice. The macro should go though the cells of a row and when the cell contains specific data it should delete the entire column. This is my code so far (probably not the right way of doing it):
Problem is that it stops after deleting the first column and I think I know what the problem is. After deleting a column, the activeCell is not on the starting row anymore and thus ActiveCell.Offset(0, 1).Range("A1").Select does not move the active cell in row 12 anymore. Can anyone help med fix this?
Regards
Kragh
I am trying to make a simple macro, but I'm stuck and need some advice. The macro should go though the cells of a row and when the cell contains specific data it should delete the entire column. This is my code so far (probably not the right way of doing it):
Code:
Sub delColumn()
Range("A12").Select
Do Until ActiveCell.Value = ""
If ActiveCell.Value = "C1" Then
ActiveCell.Columns("A:A").EntireColumn.Select
Selection.Delete Shift:=xlToLeft
ElseIf ActiveCell.Value = "C2" Then
ActiveCell.Columns("A:A").EntireColumn.Select
Selection.Delete Shift:=xlToLeft
ElseIf ActiveCell.Value = "C3" Then
ActiveCell.Columns("A:A").EntireColumn.Select
Selection.Delete Shift:=xlToLeft
End If
ActiveCell.Offset(0, 1).Range("A1").Select
Loop
End Sub
Problem is that it stops after deleting the first column and I think I know what the problem is. After deleting a column, the activeCell is not on the starting row anymore and thus ActiveCell.Offset(0, 1).Range("A1").Select does not move the active cell in row 12 anymore. Can anyone help med fix this?
Regards
Kragh