PDA

View Full Version : Deleting cell contents based on a partial formula.



klgrube
08-28-2018, 01:53 PM
Hi!

I have a spreadsheet that has 32 tabs and hundreds of rows. Many of the cells contain a formula that looks like '=if ($H1 = "ThisCompany",Q1,""). In reality, the only thing consistent about all of these formulas is the "This Company" part of the formula. The cell references can all be different (except the $H part at the beginning.) I need to write a macro that will quickly find and delete these formulas (resulting in an empty cell) if the formula contains "ThisCompany." Other cells in the same columns may have actual values and not formulas. I hope that's enough to get started with. Any suggestions? I just can't figure out through VBA how to check the partial contents of a formula.

Thanks!

p45cal
08-28-2018, 03:43 PM
This might be easier without vba, depends if it's a one-off or not.
Either select one cell (to process the entire sheet) or a range (to limit the process to that range)
Press Ctrl+f on the keyboard
Expand the find dialogue box by clicking Options > >, and have it look like this before you click Find All:
22785
Once it's found a bunch of cells, press Ctrl + a on the keyboard (this will select all those cells).
Close the Find dialogue box.
You're left with all those cells still. Press Delete on the keyboard.
QED

Be aware it might also find cells with ThisCompany in even if it's not part of a formula.

klgrube
08-28-2018, 10:28 PM
Thanks! That worked perfectly!. I had to do each of the 32 sheets separately, but it worked!