MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old May 19th, 2002, 06:03 PM   #1
elgringo56
Board Regular
 
Join Date: Apr 2002
Location: Puerto Vallarta, Mexico
Posts: 869
Default

Nate, a few weeks ago you told me about the Trim function when checking cells. Thanks for that one. You cant imagine how many hours of chaseing my tail you have saved me with that one. Do you know why, or where I can find info as to why cells will act as if they have something in them that is not there? I am curious about it is all. Thanks again
elgringo56 is offline   Reply With Quote
Old May 19th, 2002, 06:50 PM   #2
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

Hello El Gringo, not too certain it was I who mentioned the trim function. But, Excel looks at every charchter space in a string. Sometimes data transfers create visible and hidden code additions to the string.

The trim function removes all non-printable spaces from text except for single spaces between words.

e.g., =22&char(32) does not equal 22 in Excels eyes.

_________________
Cheers, NateO

[ This Message was edited by: NateO on 2002-05-19 17:52 ]
NateO is offline   Reply With Quote
Old May 19th, 2002, 07:01 PM   #3
Ivan F Moala
MrExcel MVP
 
Ivan F Moala's Avatar
 
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
Default

Quote:
On 2002-05-19 17:50, NateO wrote:
Hello El Gringo, not too certain it was I who mentioned the trim function. But, Excel looks at every charchter space in a string. Sometimes data transfers create visible and hidden code additions to the string.

The trim function removes all non-printable spaces from text except for single spaces between words.

e.g., =22&char(32) does not equal 22 in Excels eyes.

_________________
Cheers, NateO

[ This Message was edited by: NateO on 2002-05-19 17:52 ]
Hi elgringo, just to add to Nates answer.
You should also consider th CLEAN function
IF you typically download data to worksheets.
This function removes any nonprintable characters from text.
These nonprinting characters are often found in data which has been imported
from other systems such as database imports from mainframes, Html data, Web sites etc.
eg Chr(10),chr(13) etc. You can sometimes see these in the cells as
the shapes = [Squares]

Syntax =CLEAN(Text) Look up online help for this if you don't already know.

I generally run a routine when doing this;


Sub Clean_Trim()
Dim CleanTrimRg As Range
Dim oCell As Range
Dim Func As WorksheetFunction

Set Func = Application.WorksheetFunction

On Error Resume Next
Set CleanTrimRg = Selection.SpecialCells(xlCellTypeConstants, 2)
If Err Then MsgBox "No data to clean and Trim!": Exit Sub

For Each oCell In CleanTrimRg
oCell = Application.WorksheetFunction.Clean(Func.Trim(oCell))
Next


End Sub


_________________
Kind Regards,
Ivan F Moala
Have a Nice day

[ This Message was edited by: Ivan F Moala on 2002-05-19 18:03 ]
Ivan F Moala is offline   Reply With Quote
Old May 21st, 2002, 06:23 PM   #4
elgringo56
Board Regular
 
Join Date: Apr 2002
Location: Puerto Vallarta, Mexico
Posts: 869
Default

Hi Nate and Ivan. Sorry it has taken so long to get back on this, but I have been trying to research these Non printable characters to find out what they are. I have a situation where they are showing up in some stuff I am getting from a guy in San Diego. Cant find diddley on it. Ivan, thanks for the sub to clean with though, it works really well except I am such a Novice I dont really understand much of it. I have a book being brought down here next week called VBA for dummies that I hope will get me a little more started on this stuff, I find it a lot of fun. I have done a data base with it, but it is probably pretty crude since I have little knowledge of programming. Have been a hardware person all my life, never dabbled in the code. Well, thanks a lot for your help, some day I may be able to answer a few questions, also.
elgringo56 is offline   Reply With Quote
Old Aug 17th, 2002, 09:27 PM   #5
stevebausch
Board Regular
 
Join Date: May 2002
Posts: 809
Default

Here is another way of doing the clean-up, which may or not be very elegant.

Actually, after looking at the previous submission, I really don't want to post this; looks a bit clumsy.

However, it does illustrate the efforts needed to ensure that a Worksheet_Change event routine doesn't choke on multiple selections, how to loop through a multiple selection (not really elegant, though), and how to check that you aren't trying to clean-up the whole sheet, which could hang the machine.


So, here goes:


Private Sub Worksheet_Change(ByVal Target As Range)
Dim Horiz As Long, Vert As Long, HorizLoop As Long, VertLoop As Long

Const Max As Long = 100


Application.EnableEvents = False

If (VarType(Target) And vbArray) = vbArray Then
'dealing with multiple cells
Vert = UBound(Target.Value, 1)
Horiz = UBound(Target.Value, 2)
If Horiz * Vert < Max Then 'Too many cells will lock-up machine
For HorizLoop = 1 To Horiz
For VertLoop = 1 To Vert
Target.Cells(VertLoop, HorizLoop) = _
WorksheetFunction.Clean(Target.Cells(VertLoop, HorizLoop))
Next
Next
Else
MsgBox "You are trying to modify " & Horiz * Vert & " cells at a time", vbOKOnly, "Limit of " & Max & " cells"
End If

Else
Target = WorksheetFunction.Clean(Target.Cells)
End If

Application.EnableEvents = True

End Sub


[ This Message was edited by: stevebausch on 2002-08-17 20:29 ]
stevebausch is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 12:23 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes