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 6th, 2002, 10:37 AM   #1
Tyler Durden
New Member
 
Join Date: Apr 2002
Location: USA
Posts: 17
Default

I know that you can set a text length in a cell and not allow more than that amount of characters. But can you set a certain size of your cell and not allow any more text that way? For instance, if I set a cell to allow 200 characters and the user of the file spaces out their text, they may have fewer than 200 characters but some of their text may be hidden after they exit the cell. It will show up in the formula bar while typing but disappears after exit. The worksheet I have is protected. Any help?

Thanks,
Tyler Durden is offline   Reply With Quote
Old May 6th, 2002, 10:50 AM   #2
Brian from Maui
Board Regular
 
Brian from Maui's Avatar
 
Join Date: Feb 2002
Posts: 7,743
Default

Tyler,

Data validation counts spaces.
Brian from Maui is offline   Reply With Quote
Old May 6th, 2002, 10:55 AM   #3
Jack in the UK
Board Regular
 
Join Date: Feb 2002
Posts: 3,065
Default

im sure you fine text in D V is counted as any test or characters, ie symbols and spaces COUNT to:


__________________
Free Excel based Web Toolbar available here.

Jack in the UK
J & R Excel Solutions
"making Excel work for you"
Jack in the UK is offline   Reply With Quote
Old May 6th, 2002, 11:23 AM   #4
Tyler Durden
New Member
 
Join Date: Apr 2002
Location: USA
Posts: 17
Default

When I say spaces I'm talking about a full carriage return (ALT + ENTER) within a cell. If a user spaces their text that way there is a chance (because it has happened) that they enter a larger portion of text, but not too many characters. The cell expands as they are typing, but reduces to regular size after they exit. Therefore hiding certain parts of their text. Am I making sense with this?
Tyler Durden is offline   Reply With Quote
Old May 6th, 2002, 11:50 AM   #5
Jack in the UK
Board Regular
 
Join Date: Feb 2002
Posts: 3,065
Default

=LEN(A2)

this will count the number of text in a cell inc spaces...

sorry did want to add this, got disterbed by my 3 boys...

now you can work from there


__________________
Free Excel based Web Toolbar available here.

Jack in the UK
J & R Excel Solutions
"making Excel work for you"
Jack in the UK is offline   Reply With Quote
Old May 6th, 2002, 11:57 AM   #6
Brian from Maui
Board Regular
 
Brian from Maui's Avatar
 
Join Date: Feb 2002
Posts: 7,743
Default

Tyler,

How wide is your columns?
A text length of 200 is pretty wide
Brian from Maui is offline   Reply With Quote
Old May 6th, 2002, 12:05 PM   #7
Tyler Durden
New Member
 
Join Date: Apr 2002
Location: USA
Posts: 17
Default

It's a form that includes merged cells and wrapped text. This cell is actually a combination of 10 columns wide by 20 rows tall. It is one of the few sheets in the workbook that uses so much text.

Tyler Durden is offline   Reply With Quote
Old May 6th, 2002, 12:14 PM   #8
Brian from Maui
Board Regular
 
Brian from Maui's Avatar
 
Join Date: Feb 2002
Posts: 7,743
Default

Insert a comment in the cell,

Do not use ALT + Enter, or set your alignment to left align
Brian from Maui is offline   Reply With Quote
Old May 6th, 2002, 12:15 PM   #9
Jack in the UK
Board Regular
 
Join Date: Feb 2002
Posts: 3,065
Default

im sure *merge* stop this

so that the problem.


__________________
Free Excel based Web Toolbar available here.

Jack in the UK
J & R Excel Solutions
"making Excel work for you"
Jack in the UK is offline   Reply With Quote
Old May 6th, 2002, 09:20 PM   #10
Brian
Board Regular
 
Join Date: Apr 2002
Posts: 113
Default

METHOD #1:
The following will strip the "Alt-Enter" (enter this as you would normally between the quotes

=REPLACE(G7,SEARCH("
",G7),1," ")

or

=REPLACE(G7,SEARCH(CHAR(10),G7),1," ")

However, if there is no Alt-enter, then search will return N/A so you need to add If statement to accomodate this. And you can't loop, or count the number, so you need to hard code enough repetitions to cover the likely events.

METHOD #2
Easier to use a loop in a VBA macro to clean it. (two subs below are similar to what you need)

METHOD #3 - tentative
If the user enters in one cell, then you could use the trim function to display in another cell. This will strip extra spaces.

DisplayCell = trim(entryCell)

It is a little bizarre though. When
EntryCell = 1alt-enter2
Trim() = 12
but when paste special> value it still displays as 12, but then if F2 to edit the pasted location and then return to save it, the alt-enter is still there and displays as 2 lines!

MORE ON METHOD #2:
You can use VBA to strip any Alt-Enter characters, trim and then truncate at 200 characters. This macro could be run on the Worksheet_change event.

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("A10")) Is Nothing Then
trim cell "A10"
Else
do something else
End If
End Sub

Function CountElements(Txt, Separator) As String
' Counts the number of elements that are separated by a specified separator character in a text string

Dim Txt1, LastCharacter As String
Dim ElementCount As Integer, i As Integer

' Initialize
ElementCount = 0
Txt1 = Txt

' Check that the cell is not blank
If Txt1 = "" Then
CountElements = ""
Exit Function
End If

' Check if there is at least one element
If Txt1 = Separator Then
CountElements = 0
Exit Function
End If

' If the last character is not a separator, then add a separator to the end of the string
LastCharacter = Right(Txt1, 1)
If LastCharacter <> Separator Then Txt1 = Txt1 & Separator

' Extract each element
For i = 1 To Len(Txt1)
If Mid(Txt1, i, 1) = Separator Then
ElementCount = ElementCount + 1
End If
Next i
CountElements = ElementCount
End Function


Function ExtractElement(Txt, n, Separator) As String
' Returns the nth element of a text string, where the elements
' are separated by a specified separator character

Dim Txt1 As String, TempElement As String
Dim ElementCount As Integer, i As Integer

Txt1 = Txt
' If space separator, remove excess spaces
If Separator = Chr(32) Then Txt1 = Application.Trim(Txt1)

' Add a separator to the end of the string
If Right(Txt1, Len(Txt1)) <> Separator Then Txt1 = Txt1 & Separator

' Initialize
ElementCount = 0
TempElement = ""

' Extract each element
For i = 1 To Len(Txt1)
If Mid(Txt1, i, 1) = Separator Then
ElementCount = ElementCount + 1
If ElementCount = n Then
' Found it, so exit
ExtractElement = TempElement
Exit Function
Else
TempElement = ""
End If
Else
TempElement = TempElement & Mid(Txt1, i, 1)
End If
Next i
ExtractElement = ""
End Function
Brian 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 10:11 AM.


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