Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Truncate a data entry cell

I would like to truncate a cell as the user is entering data. All the number
formating techiques round the data up to the next value but I just want to
truncate it.

I see the formula =TRUNC(A1,4) will work but I cannot figure out how to use
the formula as a format. If the user is entering data into A1, it will
change A1's format to number when they enter data.

Any help will be appreciated.

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Truncate a data entry cell

I believe you would have to use VBA event code to truncate when the number
is entered.

Anything else will require a helper cell.

Example code...................no error trapping for text or dates

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A1:A10" 'edit to suit
Dim cell As Range
On Error GoTo ws_exit:
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If Len(.Value) 4 Then
.Value = Left(.Value, 4)
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub


Gord Dibben MS Excel MVP

On Mon, 16 Feb 2009 12:16:08 -0800, joerut
wrote:

I would like to truncate a cell as the user is entering data. All the number
formating techiques round the data up to the next value but I just want to
truncate it.

I see the formula =TRUNC(A1,4) will work but I cannot figure out how to use
the formula as a format. If the user is entering data into A1, it will
change A1's format to number when they enter data.

Any help will be appreciated.


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Truncate a data entry cell

That was great and quick. I have never used Macros before so it took some
time to figure out how but it works great.

One question. Is there any way to just truncate the decimal option of the
value?

I really appreciate the help. Thank you , thank you, thank you.

"Gord Dibben" wrote:

I believe you would have to use VBA event code to truncate when the number
is entered.

Anything else will require a helper cell.

Example code...................no error trapping for text or dates

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A1:A10" 'edit to suit
Dim cell As Range
On Error GoTo ws_exit:
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If Len(.Value) 4 Then
.Value = Left(.Value, 4)
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub


Gord Dibben MS Excel MVP

On Mon, 16 Feb 2009 12:16:08 -0800, joerut
wrote:

I would like to truncate a cell as the user is entering data. All the number
formating techiques round the data up to the next value but I just want to
truncate it.

I see the formula =TRUNC(A1,4) will work but I cannot figure out how to use
the formula as a format. If the user is entering data into A1, it will
change A1's format to number when they enter data.

Any help will be appreciated.



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Truncate a data entry cell

Gord,

I figured it out by writing some VB code and it works great.
Thanks again.

Joe

"Gord Dibben" wrote:

I believe you would have to use VBA event code to truncate when the number
is entered.

Anything else will require a helper cell.

Example code...................no error trapping for text or dates

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A1:A10" 'edit to suit
Dim cell As Range
On Error GoTo ws_exit:
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If Len(.Value) 4 Then
.Value = Left(.Value, 4)
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub


Gord Dibben MS Excel MVP

On Mon, 16 Feb 2009 12:16:08 -0800, joerut
wrote:

I would like to truncate a cell as the user is entering data. All the number
formating techiques round the data up to the next value but I just want to
truncate it.

I see the formula =TRUNC(A1,4) will work but I cannot figure out how to use
the formula as a format. If the user is entering data into A1, it will
change A1's format to number when they enter data.

Any help will be appreciated.



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
Control Data Entry - push entry to next cell Ofelia Excel Discussion (Misc queries) 0 July 7th 08 04:19 PM
Data Entry Online, Data Format, Data Conversion and Data EntryServices through Data Entry Outsourcing [email protected] Excel Discussion (Misc queries) 0 March 20th 08 12:45 PM
Cell Entry That Locks Selected Cells From Any Data Entry. ron Excel Worksheet Functions 5 February 16th 07 09:52 PM
Truncate within a cell [email protected] Excel Worksheet Functions 11 September 14th 06 02:21 PM
truncate the yaxis if one data point is MUCH higher than the rest steve Charts and Charting in Excel 1 October 15th 05 04:35 AM


All times are GMT +1. The time now is 12:36 PM.

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

About Us

"It's about Microsoft Excel"