Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Help please !!!!
I am trying to write some code that will trim general numbers. e.g. 123.123456789 to 123.1234 I have looked at Trim Statements but these only seem to apply to characters and spacing. Thanks Andrea |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
try =TRUNC(123.1234567,4) -- Regards Frank Kabel Frankfurt, Germany Andrea wrote: Help please !!!! I am trying to write some code that will trim general numbers. e.g. 123.123456789 to 123.1234 I have looked at Trim Statements but these only seem to apply to characters and spacing. Thanks Andrea |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Andrea,
Check the ROUND or TRUNC function. -- Regards, Tushar Mehta www.tushar-mehta.com Excel, PowerPoint, and VBA add-ins, tutorials Custom MS Office productivity solutions In article , says... Help please !!!! I am trying to write some code that will trim general numbers. e.g. 123.123456789 to 123.1234 I have looked at Trim Statements but these only seem to apply to characters and spacing. Thanks Andrea |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Frank/Tushar
Thank you for both replies - I've tried your suggestions, but I think an 'If' or 'case statement' is required. I'm a VB beginner as you may have worked out. Something like: Dim result As Variant Dim number As Variant number = Rst![Total] Result = number If number is .0000 then Trim to .0000 '(4 decimal places) frmMain.txtResult.Text = (Result) However I do not know how to write this in VB and have spent hours searching for an answer. I hope I have made this a little clearer. I would appreciate any help. Thanks Andrea -----Original Message----- Hi try =TRUNC(123.1234567,4) -- Regards Frank Kabel Frankfurt, Germany Andrea wrote: Help please !!!! I am trying to write some code that will trim general numbers. e.g. 123.123456789 to 123.1234 I have looked at Trim Statements but these only seem to apply to characters and spacing. Thanks Andrea . |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Dim result As Variant
Dim number As Variant number = Rst![Total] Result = number If len(Number) len(Format(Number,"#.0000") then Result = cdbl(format(Number,#.0000")) End if frmMain.txtResult.Text = (Result) -- Regards, Tom Ogilvy wrote in message ... Hi Frank/Tushar Thank you for both replies - I've tried your suggestions, but I think an 'If' or 'case statement' is required. I'm a VB beginner as you may have worked out. Something like: Dim result As Variant Dim number As Variant number = Rst![Total] Result = number If number is .0000 then Trim to .0000 '(4 decimal places) frmMain.txtResult.Text = (Result) However I do not know how to write this in VB and have spent hours searching for an answer. I hope I have made this a little clearer. I would appreciate any help. Thanks Andrea -----Original Message----- Hi try =TRUNC(123.1234567,4) -- Regards Frank Kabel Frankfurt, Germany Andrea wrote: Help please !!!! I am trying to write some code that will trim general numbers. e.g. 123.123456789 to 123.1234 I have looked at Trim Statements but these only seem to apply to characters and spacing. Thanks Andrea . |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
TOM
Great !!! this works a treat. Thank you...Thank you... Thank you... Andrea -----Original Message----- Dim result As Variant Dim number As Variant number = Rst![Total] Result = number If len(Number) len(Format(Number,"#.0000") then Result = cdbl(format(Number,#.0000")) End if frmMain.txtResult.Text = (Result) -- Regards, Tom Ogilvy wrote in message ... Hi Frank/Tushar Thank you for both replies - I've tried your suggestions, but I think an 'If' or 'case statement' is required. I'm a VB beginner as you may have worked out. Something like: Dim result As Variant Dim number As Variant number = Rst![Total] Result = number If number is .0000 then Trim to .0000 '(4 decimal places) frmMain.txtResult.Text = (Result) However I do not know how to write this in VB and have spent hours searching for an answer. I hope I have made this a little clearer. I would appreciate any help. Thanks Andrea -----Original Message----- Hi try =TRUNC(123.1234567,4) -- Regards Frank Kabel Frankfurt, Germany Andrea wrote: Help please !!!! I am trying to write some code that will trim general numbers. e.g. 123.123456789 to 123.1234 I have looked at Trim Statements but these only seem to apply to characters and spacing. Thanks Andrea . . |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Tushar
I have hundreds of text boxes to code. The data to populate these ranges from 1 to 10 decimal places and I need whole numbers to 0. I am new to Vb so I'm sure your suggestion will come in useful for future developments. Thanks again Andrea -----Original Message----- I imagine Tom's code does the job, but I don't see the need for a test as you want. Doesn't the following do the job? frmMain.txtResult.Text = Round(Rst![Total],4) -- Regards, Tushar Mehta www.tushar-mehta.com Excel, PowerPoint, and VBA add-ins, tutorials Custom MS Office productivity solutions In article , says... Hi Frank/Tushar Thank you for both replies - I've tried your suggestions, but I think an 'If' or 'case statement' is required. I'm a VB beginner as you may have worked out. Something like: Dim result As Variant Dim number As Variant number = Rst![Total] Result = number If number is .0000 then Trim to .0000 '(4 decimal places) frmMain.txtResult.Text = (Result) However I do not know how to write this in VB and have spent hours searching for an answer. I hope I have made this a little clearer. I would appreciate any help. Thanks Andrea -----Original Message----- Hi try =TRUNC(123.1234567,4) -- Regards Frank Kabel Frankfurt, Germany Andrea wrote: Help please !!!! I am trying to write some code that will trim general numbers. e.g. 123.123456789 to 123.1234 I have looked at Trim Statements but these only seem to apply to characters and spacing. Thanks Andrea . . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
enter numbers without decimal places | Excel Discussion (Misc queries) | |||
Why do my numbers keep going down decimal places? | Setting up and Configuration of Excel | |||
Why do my numbers keep going down decimal places? | Setting up and Configuration of Excel | |||
Sum of numbers with only two decimal places wrong | Excel Discussion (Misc queries) | |||
Subtracting two 2-decimal place numbers gives result 13-decimal places? | Excel Worksheet Functions |