Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Increase / decrease decimal - retain cell formatting


Right now I'm using the following to create shortcuts to
increase/decrease decimals:

Sub increaseDecimal()
Application.CommandBars("formatting").FindControl( ID:=398).Execute
End Sub
Sub decreaseDecimal()
Application.CommandBars("formatting").FindControl( ID:=399).Execute
End Sub

Is there a way to set this up so that a selection of cells will retain
individual cell formats?

For example:

If I have the following selected:

12.935%
$13.4
#,##0.0_)

When I use this macro it will change all of the selected cells to
either a percentage, the dollar, or other custom formats.

Thank you.


--
kbellendir
------------------------------------------------------------------------
kbellendir's Profile: http://www.excelforum.com/member.php...o&userid=15848
View this thread: http://www.excelforum.com/showthread...hreadid=273394

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Increase / decrease decimal - retain cell formatting

You can return individual number formats in a string, minipulate it (add or
remove a "0"), then reassign it back to the cell.

Too many posibilities to code for free

Sub NumberFortmatChange()
Dim i As Integer
Dim rngCell As Range
Dim strNumFormatNew As String, strNumFormatOld As String
Dim varSplit As Variant

For Each rngCell In Selection
strNumFormatOld = rngCell.NumberFormat
If Left(strNumFormatOld, Len("General")) < "General" Then
varSplit = Split(strNumFormatOld, ";")
For i = LBound(varSplit) To UBound(varSplit)
' here you can evaluate each section of the number format
' and add or delete a zero as needed
' +++++++++++++++++++++++++++++++
' there are 1,000s of possibilities
' +++++++++++++++++++++++++++++++
Next
For i = LBound(varSplit) To UBound(varSplit) - 1
' reassemble the updated number format
strNumFormatNew = varSplit(i) & ";"
Next
rngCell.NumberFormat = strNumFormatNew
End If
Next
End Sub

Hope it helps and good luck!

Dale Preuss


"kbellendir" wrote:


Right now I'm using the following to create shortcuts to
increase/decrease decimals:

Sub increaseDecimal()
Application.CommandBars("formatting").FindControl( ID:=398).Execute
End Sub
Sub decreaseDecimal()
Application.CommandBars("formatting").FindControl( ID:=399).Execute
End Sub

Is there a way to set this up so that a selection of cells will retain
individual cell formats?

For example:

If I have the following selected:

12.935%
$13.4
#,##0.0_)

When I use this macro it will change all of the selected cells to
either a percentage, the dollar, or other custom formats.

Thank you.


--
kbellendir
------------------------------------------------------------------------
kbellendir's Profile: http://www.excelforum.com/member.php...o&userid=15848
View this thread: http://www.excelforum.com/showthread...hreadid=273394


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Increase / decrease decimal - retain cell formatting

Opps, I missed something... try this

Sub NumberFortmatChange()
Dim i As Integer
Dim rngCell As Range
Dim strNumFormatNew As String, strNumFormatOld As String
Dim varSplit As Variant

For Each rngCell In Selection
strNumFormatOld = rngCell.NumberFormat
If Left(strNumFormatOld, Len("General")) < "General" Then
varSplit = Split(strNumFormatOld, ";")
For i = LBound(varSplit) To UBound(varSplit)
MsgBox varSplit(i)
Next
For i = LBound(varSplit) To UBound(varSplit) - 1
'reassemble the updated number format
strNumFormatNew = strNumFormatNew & varSplit(i) & ";"
Next
strNumFormatNew = strNumFormatNew & varSplit(UBound(varSplit))
rngCell.NumberFormat = strNumFormatNew
End If
Next
End Sub

Dale Preuss Take II

"kbellendir" wrote:


Right now I'm using the following to create shortcuts to
increase/decrease decimals:

Sub increaseDecimal()
Application.CommandBars("formatting").FindControl( ID:=398).Execute
End Sub
Sub decreaseDecimal()
Application.CommandBars("formatting").FindControl( ID:=399).Execute
End Sub

Is there a way to set this up so that a selection of cells will retain
individual cell formats?

For example:

If I have the following selected:

12.935%
$13.4
#,##0.0_)

When I use this macro it will change all of the selected cells to
either a percentage, the dollar, or other custom formats.

Thank you.


--
kbellendir
------------------------------------------------------------------------
kbellendir's Profile: http://www.excelforum.com/member.php...o&userid=15848
View this thread: http://www.excelforum.com/showthread...hreadid=273394


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Increase / decrease decimal - retain cell formatting

Maybe do each cell individually:

Option Explicit
Sub testme22()

Dim actCell As Range
Dim myRng As Range
Dim myCell As Range

Set myRng = Selection
Set actCell = ActiveCell

For Each myCell In myRng.Cells
myCell.Select
Call increaseDecimal
Next myCell

myRng.Select
actCell.Activate

End Sub

Sub increaseDecimal()
Application.CommandBars("formatting").FindControl( ID:=398).Execute
End Sub
Sub decreaseDecimal()
Application.CommandBars("formatting").FindControl( ID:=399).Execute
End Sub



kbellendir wrote:

Right now I'm using the following to create shortcuts to
increase/decrease decimals:

Sub increaseDecimal()
Application.CommandBars("formatting").FindControl( ID:=398).Execute
End Sub
Sub decreaseDecimal()
Application.CommandBars("formatting").FindControl( ID:=399).Execute
End Sub

Is there a way to set this up so that a selection of cells will retain
individual cell formats?

For example:

If I have the following selected:

12.935%
$13.4
#,##0.0_)

When I use this macro it will change all of the selected cells to
either a percentage, the dollar, or other custom formats.

Thank you.

--
kbellendir
------------------------------------------------------------------------
kbellendir's Profile: http://www.excelforum.com/member.php...o&userid=15848
View this thread: http://www.excelforum.com/showthread...hreadid=273394


--

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
Increase & Decrease Decimal Place Aaron Excel Worksheet Functions 6 December 9th 08 01:27 AM
create up and down arrows to increase and decrease value in a cell Bill Excel Worksheet Functions 1 June 13th 07 09:18 PM
increase/decrease decimal cbfinancial Excel Worksheet Functions 2 April 10th 06 10:43 PM
How do I set a cell that can increase but never decrease? Rich Excel Discussion (Misc queries) 2 November 2nd 05 06:04 PM
Increase/decrease decimal code Chris Excel Programming 3 November 19th 03 08:50 PM


All times are GMT +1. The time now is 02:27 AM.

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"