Skip to main content
deleted 1 character in body
Source Link

I am working with an excel file where in Sheet1, I need to compare column C and Column E. If in any row of sheet 1, Column C value> Column E value, then I need to delete certain column in sheet 2.

For example: If C2>E2(sheet1), I have to delete A2to A3000 of Sheet 2 If C3>E3(sheet1), I have to delete B2to B3000 of Sheet 2 and so on.

Sometimes, I may have N/A in C and E columns. But, I have to ignore these cells in case I have any error.

I have tried this code, but it does not deleteddelete columns in sheet 2. What did I do wrong?


Sub sbVBS_To_Delete_EntireColumn_C()
With ActiveWorkbook.Worksheets("Calculation")
'Worksheets("Calculation").Activate
    Dim N As Long, i As Long
    N = Cells(Rows.Count, "E").End(xlUp).Row
    On Error Resume Next
    For i = N To 2 Step -1
        If Cells(i, "C").Value >= Cells(i, "E").Value Then
           ActiveWorkbook.Worksheets("Input").Columns(i - 1).EntireColumn.Delete
        End If
    Next i
    On Error GoTo 0
End With
End Sub

enter image description here

I am working with an excel file where in Sheet1, I need to compare column C and Column E. If in any row of sheet 1, Column C value> Column E value, then I need to delete certain column in sheet 2.

For example: If C2>E2(sheet1), I have to delete A2to A3000 of Sheet 2 If C3>E3(sheet1), I have to delete B2to B3000 of Sheet 2 and so on.

Sometimes, I may have N/A in C and E columns. But, I have to ignore these cells in case I have any error.

I have tried this code, but it does not deleted columns in sheet 2. What did I do wrong?


Sub sbVBS_To_Delete_EntireColumn_C()
With ActiveWorkbook.Worksheets("Calculation")
'Worksheets("Calculation").Activate
    Dim N As Long, i As Long
    N = Cells(Rows.Count, "E").End(xlUp).Row
    On Error Resume Next
    For i = N To 2 Step -1
        If Cells(i, "C").Value >= Cells(i, "E").Value Then
           ActiveWorkbook.Worksheets("Input").Columns(i - 1).EntireColumn.Delete
        End If
    Next i
    On Error GoTo 0
End With
End Sub

enter image description here

I am working with an excel file where in Sheet1, I need to compare column C and Column E. If in any row of sheet 1, Column C value> Column E value, then I need to delete certain column in sheet 2.

For example: If C2>E2(sheet1), I have to delete A2to A3000 of Sheet 2 If C3>E3(sheet1), I have to delete B2to B3000 of Sheet 2 and so on.

Sometimes, I may have N/A in C and E columns. But, I have to ignore these cells in case I have any error.

I have tried this code, but it does not delete columns in sheet 2. What did I do wrong?


Sub sbVBS_To_Delete_EntireColumn_C()
With ActiveWorkbook.Worksheets("Calculation")
'Worksheets("Calculation").Activate
    Dim N As Long, i As Long
    N = Cells(Rows.Count, "E").End(xlUp).Row
    On Error Resume Next
    For i = N To 2 Step -1
        If Cells(i, "C").Value >= Cells(i, "E").Value Then
           ActiveWorkbook.Worksheets("Input").Columns(i - 1).EntireColumn.Delete
        End If
    Next i
    On Error GoTo 0
End With
End Sub

enter image description here

added 533 characters in body
Source Link

I am working with an excel file where in Sheet1, I need to compare column DC and Column E. If in any row of sheet 1, Column DC value> Column E value, then I need to delete certain column in sheet 2.

For example: If D2>E2C2>E2(sheet1), I have to delete A2to A3000 of Sheet 2 If D3>E3C3>E3(sheet1), I have to delete B2to B3000 of Sheet 2 and so on.

Sometimes, I may have N/A in DC and E columns. But, I have to ignore these valuescells in case I have any error.

How to write Excel VBAI have tried this code to, but it does not deleted columns in sheet 2. What did I do all these operations? Can anyone help pleasewrong?enter image description here


Sub sbVBS_To_Delete_EntireColumn_C()
With ActiveWorkbook.Worksheets("Calculation")
'Worksheets("Calculation").Activate
    Dim N As Long, i As Long
    N = Cells(Rows.Count, "E").End(xlUp).Row
    On Error Resume Next
    For i = N To 2 Step -1
        If Cells(i, "C").Value >= Cells(i, "E").Value Then
           ActiveWorkbook.Worksheets("Input").Columns(i - 1).EntireColumn.Delete
        End If
    Next i
    On Error GoTo 0
End With
End Sub

enter image description here

I am working with an excel file where in Sheet1, I need to compare column D and Column E. If in any row of sheet 1, Column D value> Column E value, then I need to delete certain column in sheet 2.

For example: If D2>E2(sheet1), I have to delete A2to A3000 of Sheet 2 If D3>E3(sheet1), I have to delete B2to B3000 of Sheet 2 and so on.

Sometimes, I may have N/A in D and E columns. But, I have to ignore these values.

How to write Excel VBA code to do all these operations? Can anyone help please?enter image description here

I am working with an excel file where in Sheet1, I need to compare column C and Column E. If in any row of sheet 1, Column C value> Column E value, then I need to delete certain column in sheet 2.

For example: If C2>E2(sheet1), I have to delete A2to A3000 of Sheet 2 If C3>E3(sheet1), I have to delete B2to B3000 of Sheet 2 and so on.

Sometimes, I may have N/A in C and E columns. But, I have to ignore these cells in case I have any error.

I have tried this code, but it does not deleted columns in sheet 2. What did I do wrong?


Sub sbVBS_To_Delete_EntireColumn_C()
With ActiveWorkbook.Worksheets("Calculation")
'Worksheets("Calculation").Activate
    Dim N As Long, i As Long
    N = Cells(Rows.Count, "E").End(xlUp).Row
    On Error Resume Next
    For i = N To 2 Step -1
        If Cells(i, "C").Value >= Cells(i, "E").Value Then
           ActiveWorkbook.Worksheets("Input").Columns(i - 1).EntireColumn.Delete
        End If
    Next i
    On Error GoTo 0
End With
End Sub

enter image description here

Source Link

How to delete a column of one sheet based on value in other sheet by ignoring N/A value?

I am working with an excel file where in Sheet1, I need to compare column D and Column E. If in any row of sheet 1, Column D value> Column E value, then I need to delete certain column in sheet 2.

For example: If D2>E2(sheet1), I have to delete A2to A3000 of Sheet 2 If D3>E3(sheet1), I have to delete B2to B3000 of Sheet 2 and so on.

Sometimes, I may have N/A in D and E columns. But, I have to ignore these values.

How to write Excel VBA code to do all these operations? Can anyone help please?enter image description here