Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Specify certain length(characters) when defining a column

Is there anyway to specify a certain character length when defining a column
in excel? The worksheet in excel has to be exported into notepad. The
notepad data has to have a predetermined amount of characters in each
column.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Specify certain length(characters) when defining a column

Set your Excel font to the same as the Notepad font. Otherwise there is no
way to measure the length.

"ktuprah" wrote in message
...
Is there anyway to specify a certain character length when defining a
column in excel? The worksheet in excel has to be exported into notepad.
The notepad data has to have a predetermined amount of characters in each
column.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Specify certain length(characters) when defining a column

You cannot enforce a maximum number of characters while the user is editing
the text in the cell, but you can check it afterwards, warn the user it is
too long an entry and then truncated it down to the maximum number of
characters you want to permit in that column. Here is example of how to
enforce a 10 character maximum length in Column C...

Private Sub Worksheet_Change(ByVal Target As Range)
Const MaxLen As Long = 10
If Target.Column = 3 And Len(Target.Value) MaxLen Then
MsgBox "Entry too long; it will be trucated to '" & _
Left(Target.Value, MaxLen) & "'."
Application.EnableEvents = False
Target.Value = Left(Target.Value, MaxLen)
Application.EnableEvents = True
End If
End Sub

To install this code, right click the tab at the bottom of the worksheet,
select View Code from the popup menu that appears and then copy/paste the
above code into the code window that appeared. Now, go back to your
worksheet and try to enter more than 10 characters into a cell in Column C.

--
Rick (MVP - Excel)


"ktuprah" wrote in message
...
Is there anyway to specify a certain character length when defining a
column in excel? The worksheet in excel has to be exported into notepad.
The notepad data has to have a predetermined amount of characters in each
column.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Specify certain length(characters) when defining a column


Data Validation in cells can check text length for you.

This sounds like you're preparing fixed-width field files, so you may
also want to pad out shorter strings to the right length. If you go for
a vba (macro) solution, take a look at RSET and LSET


--
p45cal

*p45cal*
------------------------------------------------------------------------
p45cal's Profile: 558
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=160321

Microsoft Office Help

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Specify certain length(characters) when defining a column

True, Data Validation can be used to check text length, but **only** if
typed into the cell being validated... users can Paste longer text into the
cell without triggering the validation alert... the event code I posted will
react under both situations.

--
Rick (MVP - Excel)


"p45cal" wrote in message
...

Data Validation in cells can check text length for you.

This sounds like you're preparing fixed-width field files, so you may
also want to pad out shorter strings to the right length. If you go for
a vba (macro) solution, take a look at RSET and LSET


--
p45cal

*p45cal*
------------------------------------------------------------------------
p45cal's Profile: 558
View this thread:
http://www.thecodecage.com/forumz/sh...d.php?t=160321

Microsoft Office Help


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Specify certain length(characters) when defining a column ktuprah Excel Programming 0 December 7th 09 04:49 PM
Defining a variable length area for output. JHB Excel Discussion (Misc queries) 2 August 5th 09 10:43 PM
Defining a length N1KO Excel Programming 0 February 10th 09 07:30 PM
visual basic editor- defining length of a year wheefus Excel Programming 0 January 13th 08 03:57 PM
Defining the length of an array variably franzklammer Excel Programming 4 June 21st 06 11:14 AM


All times are GMT +1. The time now is 01:22 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"