Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default round number for unknown num_digits

I want to have a control on a UserForm (scollbar, slider, other
suggestions) in which the user can select the number of decimal places
(1 through 9) or significant digits (-1 through -9) for a range of
cells. The siginficant digits is easy:

ActiveCell.Value =
Format(WorksheetFunction.Round(ActiveCell.Value, Slider1.Value), _
"#,##0")

I'm having trouble coming up with a way to do the decimal places
portion of this code. The only solution I can come up with is to use a
Select...Case for each value 1 through 9 and have the appropriate
formatting under each, which seems like the lengthy way to do things,
but I'd like to see if there's a better way.

Thanks,
Mike.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default round number for unknown num_digits

Not sure you need the format function, but anyway:

if Slider1.Value 0 then
s = "#,##0." & Application.Rept("0", Slider1.Value)
With ActiveCell
.NumberFormat = s
.Value = Format(WorksheetFunction.Round(ActiveCell.Value, Slider1.Value),
s)
End With
else



--
Regards,
Tom Ogilvy


"Michael Malinsky" wrote in message
ups.com...
I want to have a control on a UserForm (scollbar, slider, other
suggestions) in which the user can select the number of decimal places
(1 through 9) or significant digits (-1 through -9) for a range of
cells. The siginficant digits is easy:

ActiveCell.Value =
Format(WorksheetFunction.Round(ActiveCell.Value, Slider1.Value), _
"#,##0")

I'm having trouble coming up with a way to do the decimal places
portion of this code. The only solution I can come up with is to use a
Select...Case for each value 1 through 9 and have the appropriate
formatting under each, which seems like the lengthy way to do things,
but I'd like to see if there's a better way.

Thanks,
Mike.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default round number for unknown num_digits

I really don't NEED the format function, but I like to do the
formatting via code.

Anyway...this appears to do the trick...Thanks!

Tom Ogilvy wrote:
Not sure you need the format function, but anyway:

if Slider1.Value 0 then
s = "#,##0." & Application.Rept("0", Slider1.Value)
With ActiveCell
.NumberFormat = s
.Value = Format(WorksheetFunction.Round(ActiveCell.Value, Slider1.Value),
s)
End With
else



--
Regards,
Tom Ogilvy


"Michael Malinsky" wrote in message
ups.com...
I want to have a control on a UserForm (scollbar, slider, other
suggestions) in which the user can select the number of decimal places
(1 through 9) or significant digits (-1 through -9) for a range of
cells. The siginficant digits is easy:

ActiveCell.Value =
Format(WorksheetFunction.Round(ActiveCell.Value, Slider1.Value), _
"#,##0")

I'm having trouble coming up with a way to do the decimal places
portion of this code. The only solution I can come up with is to use a
Select...Case for each value 1 through 9 and have the appropriate
formatting under each, which seems like the lengthy way to do things,
but I'd like to see if there's a better way.

Thanks,
Mike.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default round number for unknown num_digits

I think that Tom's suggestion is that the line that does all the work is this
line: ".numberformat= s"

You could drop the Format() from the .value line.



Michael Malinsky wrote:

I really don't NEED the format function, but I like to do the
formatting via code.

Anyway...this appears to do the trick...Thanks!

Tom Ogilvy wrote:
Not sure you need the format function, but anyway:

if Slider1.Value 0 then
s = "#,##0." & Application.Rept("0", Slider1.Value)
With ActiveCell
.NumberFormat = s
.Value = Format(WorksheetFunction.Round(ActiveCell.Value, Slider1.Value),
s)
End With
else



--
Regards,
Tom Ogilvy


"Michael Malinsky" wrote in message
ups.com...
I want to have a control on a UserForm (scollbar, slider, other
suggestions) in which the user can select the number of decimal places
(1 through 9) or significant digits (-1 through -9) for a range of
cells. The siginficant digits is easy:

ActiveCell.Value =
Format(WorksheetFunction.Round(ActiveCell.Value, Slider1.Value), _
"#,##0")

I'm having trouble coming up with a way to do the decimal places
portion of this code. The only solution I can come up with is to use a
Select...Case for each value 1 through 9 and have the appropriate
formatting under each, which seems like the lengthy way to do things,
but I'd like to see if there's a better way.

Thanks,
Mike.


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default round number for unknown num_digits

Well then I learned something...I didn't know that .numformat existed.

Thanks!

Dave Peterson wrote:
I think that Tom's suggestion is that the line that does all the work is this
line: ".numberformat= s"

You could drop the Format() from the .value line.



Michael Malinsky wrote:

I really don't NEED the format function, but I like to do the
formatting via code.

Anyway...this appears to do the trick...Thanks!

Tom Ogilvy wrote:
Not sure you need the format function, but anyway:

if Slider1.Value 0 then
s = "#,##0." & Application.Rept("0", Slider1.Value)
With ActiveCell
.NumberFormat = s
.Value = Format(WorksheetFunction.Round(ActiveCell.Value, Slider1.Value),
s)
End With
else



--
Regards,
Tom Ogilvy


"Michael Malinsky" wrote in message
ups.com...
I want to have a control on a UserForm (scollbar, slider, other
suggestions) in which the user can select the number of decimal places
(1 through 9) or significant digits (-1 through -9) for a range of
cells. The siginficant digits is easy:

ActiveCell.Value =
Format(WorksheetFunction.Round(ActiveCell.Value, Slider1.Value), _
"#,##0")

I'm having trouble coming up with a way to do the decimal places
portion of this code. The only solution I can come up with is to use a
Select...Case for each value 1 through 9 and have the appropriate
formatting under each, which seems like the lengthy way to do things,
but I'd like to see if there's a better way.

Thanks,
Mike.


--

Dave Peterson




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
Finding the unknown number sierra spiegel Excel Worksheet Functions 6 November 15th 09 05:40 AM
Finding Unknown number sierra spiegel Excel Worksheet Functions 1 November 14th 09 01:11 AM
FINDING THE UNKNOWN NUMBER sierra spiegel Excel Worksheet Functions 3 November 13th 09 11:33 PM
SUM IF - What if column number is unknown Milind Keer[_2_] Excel Discussion (Misc queries) 3 October 23rd 08 05:22 PM
Unknown number format Don Excel Worksheet Functions 1 September 20th 06 06:17 PM


All times are GMT +1. The time now is 11:54 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"