How to remove blank spaces from a copied webpage table

huh?

Board Regular
Joined
Aug 3, 2004
Messages
72
Hi
Description of Problem:
Copied and pasted an internet webpage table into a worksheet. (There are going to be multiple workbooks, with multiple worksheets, each worksheet containing one table that has been pasted.) All cells have what appears to be a space before the beginning of the value, whether numeric or text. I am trying to find a better way to remove these spaces rather than individually going thru each cell and deleting these leading spaces. These spaces have to be removed from the numeric values otherwise summing them (from a column) into a cell, at the bottom, doesn't work.

Solutions Attempted:
1) Used Trim function in following manner. A1:D100 were the cells I wished to trim. In cell E1 put =TRIM(A1) in it. Then copied cell E1 and then selected cells E1:H100. Right-click and pasted. I had now trimmed all of the columns. Then I selected E1:H100 and did copy. Then selected A1:D100 and did paste special, and selected Values. Problem was the spaces weren't gone.
2) Tried Clean instead, just like above, and unfortunately, with the same lack of results.
3) I assumed at this point the blank was char 160, so I used the following function in cell E1 to get rid of the character: =SUBSTITUTE(A1,CHAR(160),"")
The message, "No Ref" was displayed in the cell.

So now I am at a loss at what to do. For those of you who would suggest a VBA solution, I wouldn't mind using VBA, but not sure what to do once a function has been placed in a standard module. i.e. If I use/put the function in a cell on the same worksheet, will it then automatically run the function and format the sheet. Any help would be greatly appreciated. Thanks
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Try pasting a sample of the text to a blank sheet in Cell B7, then put this code in E7 and copy accross one column for each character in the string.

=MID($B7,COLUMN()-COLUMN($D7),1)
This will string the text out one character per cell.

Below that put:
=Code(E7)
and copy accross. Look beneith the cell containing the blank and it will give you the CHAR() number of the blank.

This won't clean them but it will help you identify the offending spaces.
 
Upvote 0
Thank you. Below is the result of checking char code. As you can see, the space that I am trying to remove is char 160. They're not lining up properly, but 160 is for the blank space at the beginning.
  $ 3 6 . 6 9
160 36 51 54 46 54 57

So why did the code I used initially in step 3 to remove char 160 not work? What is the most efficient way to clean up the data when dealing with multiple sheets? Appreciate the help.
 
Upvote 0
Hello HuH
TO GET RID OF SPACES ...

To get rid of spaces just use the Replace tool found on the Edit Menu.

in the Find Text box hit the space bar once to tell it your looking for spaces... in the replace text box put nothing to tell it to replace spaces with nothing ... boomba your done
 
Upvote 0
umm thanks Nimrod, but the space is actually char 160, so replacing spaces doesn't work. Any other suggestions?
 
Upvote 0
To change number strings to actual numbers do the following .
1. put the number 1 in an empty cell
2. Select the cell with number 1 in it and select copy
3. Bring up Goto window by pressing F5 key
4. in the GoTo window click “Special..”
5. In “Special Window” select the “Constants” Checkbox and click OK
6. Now that all cells with constants in them have been highlighted …
7. Right click on one of the selectes cells and Select “Paste Special”
8. in “Paste Special “ select multiply and then OK…
9. Boomba done .
 
Upvote 0
This Macro will go thru active sheet and replace all Chr (160) values with nothing

Sub ReplaceChr160()
Cells.Replace What:=Chr(160), Replacement:="", LookAt:=xlPart, SearchOrder:= _
xlByRows, MatchCase:=False
End Sub
 
Upvote 0
The following Macro ...
1) Removes all chr 160 from strings on activeSheet
2) Uses PasteSpecial Multiply to change number strings into actual numbers

Public Sub MakeStringsIntoNumbers()
' get rid of spaces eg Chr 160
Cells.Replace What:=Chr(160), Replacement:="", LookAt:=xlPart, SearchOrder:= _
xlByRows, MatchCase:=False
' use paste special to make number strings actual numbers
CellToCopy = Cells(65536, 1).End(xlUp).Offset(1, 0).Address
Range(CellToCopy).Value = 1
Range(CellToCopy).Copy
Cells.SpecialCells(xlCellTypeConstants, 2).PasteSpecial Paste:=xlAll, Operation:=xlMultiply, SkipBlanks:= _
False, Transpose:=False
Range(CellToCopy).ClearContents
End Sub
 
Upvote 0
BJungheim/huh,

A easy way to determine the characters in a cell is to use Chip Pearson’s “Cell View” add-in. The add-in allows you to see the exact characters in a cell (including non-printable characters), as well as hex codes.
http://www.cpearson.com/excel/CellView.htm

When you install this add in, it will add an item to your View menu called "View Cell Contents". Select a cell then click the menu item to display a dialog box that shows the cell’s contents, together with the character codes.

Regards,

Mike
 
Upvote 0

Forum statistics

Threads
1,214,823
Messages
6,121,777
Members
449,049
Latest member
greyangel23

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