Conditional Delete Cells to the Right

learnerspermit

New Member
Joined
Apr 22, 2011
Messages
7
Hello, I was wondering if anyone knows how to do this:

If cell A1 does not contains the words "account", "fund", or "number" than delete cells to the right until cell A1 does contain "account", "fund", or "number"

Thanks for any help!
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Yes, exactly ... if A1 does not contain "account", "fund", or "number" than delete it and move all the cells to the right, left one cell, e.g. B1 goes to A1 and C1 goes to B1, etc., etc. until A1 does contain "account", "fund", or "number"
 
Upvote 0
Basically, what happened is I imported a .csv file and when cells contained more than a certain number of characters, it split it into multiple cells. But I need the columns to line up correctly, so I would just like to delete the extra cells that were created. I could do this for a few cells manually, but this worksheet is pretty long.
 
Upvote 0
here you go. it stops if it has those things you said OR if it's blank
PHP:
Sub Account_or_something()
    Do While [a1] <> "account" And [a1] <> "fund" And [a1] <> "number" And [a1] <> ""
        [a1].Delete shift:=xlToLeft
    Loop
End Sub
 
Upvote 0
I apologize for this rudimentary question, but what if I wanted to continue doing this for A1, A2, A3, etc., etc., until all the rows are fixed, i.e. do the same thing as above, but for the entire column? Again, thanks so much!
 
Upvote 0
So, if after A1 contains "account", "fund", or "number", go to A2 and delete A2 until A2 contains "account", "fund", or "number", and then go to A3 and delete A3 until A3 contains "account", "fund", or "number"
 
Upvote 0
PHP:
Sub Account_Stuffs2()
LC = Cells(1, Columns.Count).End(xlToLeft).Column
    For i = LC To 1 Step -1
        If Cells(1, i) <> "account" And Cells(1, i) <> "fund" And Cells(1, i) <> "number" Then
            Cells(1, i).Delete shift:=xlToLeft
        End If
    Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,827
Members
452,946
Latest member
JoseDavid

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