Hi people,
I'm currently writing some code that I want to do many things, but one of them is to loop through the cells A1 to J1 while checking the value, if it is equivalent to some set values, it deletes the entire column. Right now, the code "works" but it stops and gives me an error 424 everytime the code deletes a column. After it does, I need to restart it everytime for it to work. How can I stop this?
This is my current code:
Sub Automation()
Set Mr = Range("A1:J1")
For Each cell In Mr
If cell.Value = "#" Then cell.EntireColumn.Delete
If cell.Value = "Coupler Detached" Then cell.EntireColumn.Delete
If cell.Value = "Coupler Attached" Then cell.EntireColumn.Delete
If cell.Value = "Host Connected" Then cell.EntireColumn.Delete
If cell.Value = "End Of File" Then cell.EntireColumn.Delete
Next
End Sub
I'm currently writing some code that I want to do many things, but one of them is to loop through the cells A1 to J1 while checking the value, if it is equivalent to some set values, it deletes the entire column. Right now, the code "works" but it stops and gives me an error 424 everytime the code deletes a column. After it does, I need to restart it everytime for it to work. How can I stop this?
This is my current code:
Sub Automation()
Set Mr = Range("A1:J1")
For Each cell In Mr
If cell.Value = "#" Then cell.EntireColumn.Delete
If cell.Value = "Coupler Detached" Then cell.EntireColumn.Delete
If cell.Value = "Coupler Attached" Then cell.EntireColumn.Delete
If cell.Value = "Host Connected" Then cell.EntireColumn.Delete
If cell.Value = "End Of File" Then cell.EntireColumn.Delete
Next
End Sub