And you really used Format|Style... to create these styles?
If yes, then this may work for you.
Option Explicit
Sub testme()
Dim StyleNamesToChange As Variant
Dim iCtr As Long
Dim WorkedOk As Boolean
StyleNamesToChange = Array("test1") ', "test2")
For iCtr = LBound(StyleNamesToChange) To UBound(StyleNamesToChange)
WorkedOk = ChangeNumberFormatInStyle(WhatWorkbook:=ActiveWorkbook, _
StyleName:=CStr(StyleNamesToChange(iCtr)), IncreaseDec:=True)
If WorkedOk = False Then
MsgBox StyleNamesToChange(iCtr) & " failed"
End If
Next iCtr
End Sub
Function ChangeNumberFormatInStyle(WhatWorkbook As Workbook, _
StyleName As String, IncreaseDec As Boolean) As Boolean
Dim TestStyle As Style
Dim OldNumberFormat As String
Dim NewNumberFormat As String
Dim cCtr As Long
Dim WorkedOk As Boolean
Set TestStyle = Nothing
On Error Resume Next
Set TestStyle = WhatWorkbook.Styles(StyleName)
On Error GoTo 0
WorkedOk = False
If TestStyle Is Nothing Then
'not used
Else
OldNumberFormat = TestStyle.NumberFormat
NewNumberFormat = ""
For cCtr = Len(OldNumberFormat) To 1 Step -1
If IncreaseDec = True Then
'look for a 0 or decimal point
If Mid(OldNumberFormat, cCtr, 1) = "0" _
Or Mid(OldNumberFormat, cCtr, 1) = "." Then
NewNumberFormat = Left(OldNumberFormat, cCtr) _
& "0" & Mid(OldNumberFormat, cCtr + 1)
'and stop looking
Exit For
Else
'keep looking
End If
Else
If Mid(OldNumberFormat, cCtr, 1) = "0" Then
'delete it
NewNumberFormat = Left(OldNumberFormat, cCtr - 1) _
& Mid(OldNumberFormat, cCtr + 1)
'and stop looking
Exit For
End If
End If
Next cCtr
If NewNumberFormat = "" Then
'last 0 wasn't found, do nothing
Else
On Error Resume Next
TestStyle.NumberFormat = NewNumberFormat
If Err.Number = 0 Then
WorkedOk = True
Else
Err.Clear
End If
On Error GoTo 0
End If
End If
ChangeNumberFormatInStyle = WorkedOk
End Function
There's not a lot of validation going on, so test it before you trust it.
If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
There are two parts to this--the sub is what starts it -- the sub calls the
function that does the work.
You'd change this line:
StyleNamesToChange = Array("test1", "test2")
To list the style names that you want to change.
In this line, the
WorkedOk = ChangeNumberFormatInStyle(WhatWorkbook:=ActiveWorkbook, _
StyleName:=CStr(StyleNamesToChange(iCtr)), IncreaseDec:=True)
True means to increment the number of decimal places.
False will decrement them.