VBA Help - Deleting Certain Values From Rows

Pineapple_Crazy

Board Regular
Joined
May 2, 2017
Messages
51
Hey Everyone,

Looking for some VBA help here. Basically I have this disgusting looking output from one of our management systems. I have created code to clean the data up into a presentable table format that can be utilized to draw some analysis. However, in doing so I have brought certain values into the data set rows that I would like to remove. I've developed some code to do so, shown below, but it is incredibly slow and it doesn't remove all the values at once (not really sure why?). Therefore, I need to loop through the code like 5 times in order to remove all the values I need removed. Can someone provide some assistance on how to improve this code and maybe get away from the looping? Thanks much!


Code:
Sub Find_Values_Delete()

Dim Mycell As Range
Let x = 0
Do While x < 5


Application.DisplayAlerts = False
Application.ScreenUpdating = False
    
    
For Each Mycell In Range("A1:AM100000")
    
    If Mycell.Value = "Account #:" Then
        Mycell.Delete Shift:=xlToLeft
    End If
    
    If Mycell.Value = "1099:" Then
        Mycell.Delete Shift:=xlToLeft
    End If
        
    If Mycell.Value = "SSN:" Then
        Mycell.Delete Shift:=xlToLeft
    End If
          
    If Mycell.Value = "Tax ID:" Then
        Mycell.Delete Shift:=xlToLeft
    End If
    
    If Mycell.Value = "Null" Then
        Mycell.Delete Shift:=xlToLeft
    End If
    


Next
 x = x + 1
 
Loop




Application.ScreenUpdating = True
Application.DisplayAlerts = True


End Sub
 
No loops, really? :twisted:
Sorry, I guess I should clarify it and say "no looping through all the cells of data on the sheet".
I think even you would agree that looping through an array of values is better than writing the same block of code 5 times in VBA!;)
 
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,223,247
Messages
6,171,007
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top