View Full Version : toggling between styles
lior03
08-31-2006, 12:15 AM
hello
i want to present data in various styles.
selection.Style = "jon"
this style round a figure to the the nearest 1,000.
i want to add a botton which will toggle between this style and a normal style which will present figures as they are.
one click - 'jon' one click - normal and so on.
thanks
Killian
08-31-2006, 01:47 AM
Then your click event should run something likeWith Selection
If .Style = "Normal" Then
.Style = "jon"
Else
.Style = "Normal"
End If
End With
lior03
09-06-2006, 02:31 AM
hello
as i said i have a style named jon.i'ts number format is:
#,###,",000"
i am trying to round figures using this style to the nearest thousenth.
why do it round
96,45723,46544,796164,718
to
96,00023,00045,000165,000
is there a way in vba to do the roundig correctley?
lior03
10-07-2006, 01:30 PM
what's wrong with:
If selection.Formula = "=SUM(ROUND(R[-2]C:R[-1]C,-3))" Then
selection.FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"
Else
selection.Formula = "=SUM(ROUND(R[-2]C:R[-1]C,-3))"
End If
assumig i want to present information in various ways- rounded or not.
thanks
mdmackillop
10-07-2006, 02:27 PM
Hi Moshe,
Excel number precision is limited to 15 digits.
lior03
10-11-2006, 06:11 AM
hello
how can i enable the user select a number format he want to present data in just one click?
lenze
10-11-2006, 10:23 AM
Try using the Before-DoubleClick event instead.
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Count > 1 Then Exit Sub
If Target.Style = "Normal" Then
Target.Style = "Jon"
Else: Target.Style = "Normal"
End If
Cancel = True
End Sub
Your style is correct if formatted as indicated. It rounds 45723 to 46,000
If you don't want the 000s, change the style format to #,"M" which rounds 45723 to 46M.
HTH
lenze
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.