Re: Large worksheet formatting: change % formats only?
From: Bill Weylock (bill_at_nospam.net)
Date: 01/05/05
- Next message: Bill Weylock: "Re: Large worksheet formatting: change % formats only?"
- Previous message: JE McGimpsey: "Re: Wrap Text with a Merged Cell!"
- In reply to: J Laroche: "Re: Large worksheet formatting: change % formats only?"
- Next in thread: J Laroche: "Re: Large worksheet formatting: change % formats only?"
- Reply: J Laroche: "Re: Large worksheet formatting: change % formats only?"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 05 Jan 2005 08:52:59 -0800
That is so great.
Hope I can do something for you sometime. Considering the gap in expertise
... Need your sock drawer arranged?
Thanks so much!
Best,
- Bill
On 1/5/05 3:14 AM, in article BE013648.5CF5%j.laro@NsOySmPpAaMtico.ca, "J
Laroche" <j.laro@NsOySmPpAaMtico.ca> wrote:
> The macro stopped on a cell in which 100.00% was directly typed instead of
> being the result of a formula. You can bypass the problem with this new
> version, which will ignore those cells without a formula. However if the
> cellıs formula is =1 (or any other value with the 0.00% format), the result
> will be correct but left-aligned, so you can spot it easily.
>
> Sub convert_percent()
> d = Application.International(xlDecimalSeparator)
> For Each c In ActiveSheet.UsedRange.Cells
> If c.NumberFormat = "0.00%" And Application.IsNumber(c.Value) Then
> f = Right(c.Formula, Len(c.Formula) - 1)
> If f <> "" Then
> c.Formula = "=TEXT(" & f & ",LEFT(""0" & d & _
>>> "00"",1 + 2*(MOD(ROUND(" & f & _
>>> "*100,2),1)>0) + (MOD(ROUND(" & f & _
>>> "*1000,1),1)>0)) & ""%"")"
>>> c.NumberFormat = "General"
> End If
> End If
> Next
> End Sub
>
>
>
> JL
> Mac OS X 10.3.7, Office v.X 10.1.6
>
>
> Bill Weylock wrote on 2005/01/04 22:48:
>
>> Thanks so much.
>>
>> That is exactly what I needed!
>>
>> Only thing is that I am a stumblebum novice at using macros. I may have
>> screwed something up, or there may be a tiny error somewhere in the macro.
>>
>> I created a VBA module in the workbook, pasted your code into it, and saved
>> it.
>>
>> When I started to run it, things hummed along for a few seconds, but then I
>> got an error:
>>
>> Run-time error 1004ı
>>
>> Application-defined or object-defined error.
>>
>> I clicked the Debug button and selected ³Step through².
>>
>> The four lines I have just colored red below were in white against a red
>> background.
>>
>> I read the help message, but itıs over my head.
>>
>> When I looked at the worksheet, most of the first table had been reformatted
>> perfectly. Looks as if it worked fine until it encountered 100.00%. Could
>> that be the problem? Wasnıt looking for three digits to the left of the
>> decimal?
>>
>> Thanks so much again!
>>
>>
>> Best,
>>
>>
>> - Bill
>>
>>
>> On 1/4/05 7:14 PM, in article BE00C5B7.5CE9%j.laro@NsOySmPpAaMtico.ca, "J
>> Laroche" <j.laro@NsOySmPpAaMtico.ca> wrote:
>>
>>> JE McGimpsey wrote on 2005/01/04 15:01:
>>>
>>>> > In article <BE003363.20BA5%bill@nospam.net>,
>>>> > Bill Weylock <bill@nospam.net> wrote:
>>>> >
>>>>> >> The formula results are exactly what I want. When I try to apply it,
>>>>> >> however, it produces a cell not formatted as a percent. I can get the
>>>>> result
>>>>> >> I want only by manually applying a % format with the number of places I
>>>>> >> need.
>>>> >
>>>> >
>>>> > Whoops - you're exactly right - I'd applied one of the custom formats
>>>> > first. Remove the VALUE(...) wrapper. It produces text, but can be
>>>> > coerced to values if needed in subsequent calculations.
>>>
>>>
>>> Bill, since you have a very large number of cells to reformat (or
>>> reformulate), a macro can do the job for you. Copy the code below in a
>>> module, then when the sheet to reformat is the active one execute the macro.
>>> The cells will still contain their original formula, so even if source data
>>> is changed data will stay up-to-date.
>>>
>>>
>>> Sub convert_percent()
>>> d = Application.International(xlDecimalSeparator)
>>> For Each c In ActiveSheet.UsedRange
>>> If c.NumberFormat = "0.00%" And Application.IsNumber(c.Value) Then
>>> f = Right(c.Formula, Len(c.Formula) - 1)
>>> c.Formula = "=TEXT(" & f & ",LEFT(""0" & d & _
>>> "00"",1 + 2*(MOD(ROUND(" & f & _
>>> "*100,2),1)>0) + (MOD(ROUND(" & f & _
>>> "*1000,1),1)>0)) & ""%"")"
>>> c.NumberFormat = "General"
>>> End If
>>> Next
>>> End Sub
>>>
>>>
>>> JL
>>> Mac OS X 10.3.7, Office v.X 10.1.6
>>>
>>
>>
>>
>>
>> Panther 10.3.6
>> Office 2004
>> Windows XP Pro SP2
>> Office 2003
>>
>>
>
>
Panther 10.3.6
Office 2004
Windows XP Pro SP2
Office 2003
- Next message: Bill Weylock: "Re: Large worksheet formatting: change % formats only?"
- Previous message: JE McGimpsey: "Re: Wrap Text with a Merged Cell!"
- In reply to: J Laroche: "Re: Large worksheet formatting: change % formats only?"
- Next in thread: J Laroche: "Re: Large worksheet formatting: change % formats only?"
- Reply: J Laroche: "Re: Large worksheet formatting: change % formats only?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|