dslreports logo
site
 
    All Forums Hot Topics Gallery
spc

spacer




how-to block ads


Search Topic:
uniqs
226
share rss forum feed

LLigetfa

join:2006-05-15
Fort Frances, ON
kudos:1

Find and Replace TAB character in cells

The word TAB being so popular makes for a tough google search so not finding joy. I have a report that has the TAB character in the middle of a string that I need to remove as part of the string.

Using special chars like ^t or ^9 don't cut it.

Oh, it is Excel 2003 if that matters.


jupitermoon

join:2011-09-27

Press Ctrl-F to open the Find dialog. Hold down the Alt key, type 0009 in the Find what field using the numeric keypad, and release the Alt key. Click on Find Next.

If you're using a laptop and don't have a numeric keypad, press Fn and NumLk key before you do this.

Or you could use Excel's CLEAN function to remove all nonprintable characters from a string.


LLigetfa

join:2006-05-15
Fort Frances, ON
kudos:1

I did try [alt]0009 but that did not work. Maybe that only works in versions of Excel newer than 2003. I can use a formula but that doesn't replace in the original cell but rather populates the change to an adjacent cell. Does CLEAN work on the cell in place?

I may have to delve into VBA macros...
--
Strange as it seems, no amount of learning can cure stupidity, and formal education positively fortifies it. -- Stephen Vizinczey


jupitermoon

join:2011-09-27

CLEAN removes the first 32 nonprintable ASCII characters, but it doesn't work on the cell in place.

What happens if you press Ctrl+H, type CHAR(9) in the Find what field, and then click on Find All?

If that finds the TAB characters, enter whatever you like in the Replace with field surrounded by quotes (for example, "ZZ" or " " for a space or "" for nothing) and then click on Replace All.


LLigetfa

join:2006-05-15
Fort Frances, ON
kudos:1

CHAR(9) is taken literally so that won't work. Short of a macro, I think there is no other way, at least not through the Find and Replace UI. Thanks for trying though.

That said, in this particular case the TAB char is preceded by a consistent and unique char sequence that I can use in my find and I can substitute the TAB with the single char wildcard ? so I have a workaround.
--
Strange as it seems, no amount of learning can cure stupidity, and formal education positively fortifies it. -- Stephen Vizinczey


jupitermoon

join:2011-09-27

We get different results, but it's probably due to how the characters got entered.

Find what: CHAR(9) works for me if I enter the characters in the cells directly.

Cells A1:C1 contain CHAR(9) + text + CHAR(9). CHAR(9) is the TAB character. It doesn't display.

The first picture shows the results for Find All using Find what: CHAR(9).

If I enter the TAB characters in Notepad via Alt+0009 (typed with NumLk on) and then paste them into Excel, Find what: CHAR(9) does not find them. But Find what: Alt+0009 (typed with NumLk on) does find them.

Cell A3 contains the letters T + Alt-0009 + the letter h + Alt-0009 + the letter e (copied from Notepad). In this case the TAB character does display.

The second picture shows the results for Find All using Find what: Alt+0009 (typed with NumLk on).

Are you sure the character is a TAB character? You can use the Cell View add-in to check:

»www.cpearson.com/excel/CellView.aspx

But, as you said, if you have a unique string before the TAB character, you may be good to go.

LLigetfa

join:2006-05-15
Fort Frances, ON
kudos:1

I think your Excel may be newer. Mine is 2003.

I am sure it is Char(9) cuz the formula:
=Substitute(A3,char(9),char(32))
changes it to a space albeit not in the same cell.

Also, I copy/pasted the cell contents into notepad, saved it as a txt file, and then iterated through each Char with a script which returned asc(9) for it.
--
Strange as it seems, no amount of learning can cure stupidity, and formal education positively fortifies it. -- Stephen Vizinczey


jupitermoon

join:2011-09-27

Both of these methods work in Excel 2003 and Excel 2007 for me.

Is the TAB character visible? If so, have you tried copying and pasting it into the Find what field using Ctrl-V. Sometimes that won't work, but this does work, for me, in both versions of Excel.

If you have a sample file with just a couple of cells with the TAB character, I'd be happy to take a look at it. No promises though...


LLigetfa

join:2006-05-15
Fort Frances, ON
kudos:1

In the cell it shows as a rectangle and yes, I did try copying it with Ctrl-C and pasting it into the find field. Copy/pasting even the entire cell contents fails to find it.

If it's not the version, maybe we are on different SP or patch levels, or maybe the OS version is a factor.
--
Strange as it seems, no amount of learning can cure stupidity, and formal education positively fortifies it. -- Stephen Vizinczey



thephantom

join:2001-04-24
Alamo, CA
reply to LLigetfa

said by LLigetfa:

=Substitute(A3,char(9),char(32))

If that works for you, just put it in a helper cell in the next available column. For example, if it is col A, either pick the next blank column that exists or insert one next to col A. Put that formula in row 3 of the column and copy the formula down to the end of data in col A. Then select all of the cells in that helper column and copy them (ctl-c). Then select the first cell in col A (A3 in your example) and from the menu, chose edit-paste special, and then pick the "values" radio button. Poof done. And then you can clean up by getting rid of the extra helper column.

LLigetfa

join:2006-05-15
Fort Frances, ON
kudos:1

Thanks for the tip.