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!
 
Thanks rsxchin! I wish I could program like that!

If you have time, I have one last question on this topic:

What if I wanted to do the exact same thing, but start with cell I8 instead of A1?

So it would check I8 to see if it contains "account", "fund", or "number" and if not it would delete I8 and move cells to the right (same row) to the left one and then check again to see if I8 contains "account", "fund", or "number". Then once it does, it would move on to I9 to see if it contains "account", "fund", or "number" and if not would do the same thing as above until it did, and once it does, move on to I10 and do the same, etc., etc., until it gets to the last row in the column.
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
My windows decided to crap out, so I'm doing this by hand and without the ability to test it. Let me know if it doesn't work out for you.
PHP:
Sub Account_Stuffs3()
LC = Cells(9, Columns.Count).End(xlToLeft).Column
    For i = LC To 8 Step -1
        If Cells(9, i) <> "account" And Cells(9, i) <> "fund" And Cells(9, i) <> "number" Then
            Cells(9, i).Delete shift:=xlToLeft
        End If
    Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
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