Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default getting rid of trailing zeroes

How can I use the numberformat property as such:

1.000 becomes 100%
0.547 becomes 54.7%

i currently have .numberformat = "0.#%", which gives

1.000 - 100.% (dangling decimal point)
0.547 - 54.7% (correct)

..numberformat = "0.0%" gives
1.000 - 100.0% (dangling zero)
0.547 - 54.7% (correct)

wazooli
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default getting rid of trailing zeroes

Dim myValue as double
dim myNumberFormat as string

myValue = 1.000

if clng(myvalue) * 100 = myvalue * 100 then
mynumberformat = "##0"
else
mynumberformat = "##0.0"
end if



Wazooli wrote:

How can I use the numberformat property as such:

1.000 becomes 100%
0.547 becomes 54.7%

i currently have .numberformat = "0.#%", which gives

1.000 - 100.% (dangling decimal point)
0.547 - 54.7% (correct)

.numberformat = "0.0%" gives
1.000 - 100.0% (dangling zero)
0.547 - 54.7% (correct)

wazooli


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default getting rid of trailing zeroes

I need to fit it into the existing code I have:

Sub Btn_click()
Dim rng As Range
Dim decide As Double

Set rng = Selection

If rng.Areas.count 1 Then Exit Sub
If rng.Columns.count 1 Then Exit Sub
If Application.count(rng) = 0 Or Application.Max(rng) = 0 Then
MsgBox "No numbers"
Exit Sub
End If
With rng.Offset(0, 1)
.Formula = "=" & rng(1).Address(0, 0) & "/max(" & rng.Address & ")"
.HorizontalAlignment = xlCenter
.NumberFormat = "0.#%"
End With

End Sub
(code supplied kindly by Tom O., modified slightly by me)

wazooli

"Dave Peterson" wrote:

Dim myValue as double
dim myNumberFormat as string

myValue = 1.000

if clng(myvalue) * 100 = myvalue * 100 then
mynumberformat = "##0"
else
mynumberformat = "##0.0"
end if



Wazooli wrote:

How can I use the numberformat property as such:

1.000 becomes 100%
0.547 becomes 54.7%

i currently have .numberformat = "0.#%", which gives

1.000 - 100.% (dangling decimal point)
0.547 - 54.7% (correct)

.numberformat = "0.0%" gives
1.000 - 100.0% (dangling zero)
0.547 - 54.7% (correct)

wazooli


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default getting rid of trailing zeroes

Maybe...

Option Explicit

Sub Btn_click()
Dim rng As Range
Dim decide As Double

Dim myValue As Double
Dim myNumberFormat As String

Set rng = Selection

If rng.Areas.Count 1 Then Exit Sub
If rng.Columns.Count 1 Then Exit Sub
If Application.Count(rng) = 0 Or Application.Max(rng) = 0 Then
MsgBox "No numbers"
Exit Sub
End If

With rng.Offset(0, 1)
.Formula = "=" & rng(1).Address(0, 0) & "/max(" & rng.Address & ")"

myValue = .Value
If CLng(myValue) * 100 = myValue * 100 Then
myNumberFormat = "0%"
Else
myNumberFormat = "0.#%"
End If

.HorizontalAlignment = xlCenter
.NumberFormat = myNumberFormat
End With

End Sub




Wazooli wrote:

I need to fit it into the existing code I have:

Sub Btn_click()
Dim rng As Range
Dim decide As Double

Set rng = Selection

If rng.Areas.count 1 Then Exit Sub
If rng.Columns.count 1 Then Exit Sub
If Application.count(rng) = 0 Or Application.Max(rng) = 0 Then
MsgBox "No numbers"
Exit Sub
End If
With rng.Offset(0, 1)
.Formula = "=" & rng(1).Address(0, 0) & "/max(" & rng.Address & ")"
.HorizontalAlignment = xlCenter
.NumberFormat = "0.#%"
End With

End Sub
(code supplied kindly by Tom O., modified slightly by me)

wazooli

"Dave Peterson" wrote:

Dim myValue as double
dim myNumberFormat as string

myValue = 1.000

if clng(myvalue) * 100 = myvalue * 100 then
mynumberformat = "##0"
else
mynumberformat = "##0.0"
end if



Wazooli wrote:

How can I use the numberformat property as such:

1.000 becomes 100%
0.547 becomes 54.7%

i currently have .numberformat = "0.#%", which gives

1.000 - 100.% (dangling decimal point)
0.547 - 54.7% (correct)

.numberformat = "0.0%" gives
1.000 - 100.0% (dangling zero)
0.547 - 54.7% (correct)

wazooli


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default getting rid of trailing zeroes

Doesn't work. I guess what I need to do is extract each cell in the range
individually, and format according to whether there is a trailing zero or
not. The question is...

if rng = selection, how do i get individual cell.value information out?

"Dave Peterson" wrote:

Maybe...

Option Explicit

Sub Btn_click()
Dim rng As Range
Dim decide As Double

Dim myValue As Double
Dim myNumberFormat As String

Set rng = Selection

If rng.Areas.Count 1 Then Exit Sub
If rng.Columns.Count 1 Then Exit Sub
If Application.Count(rng) = 0 Or Application.Max(rng) = 0 Then
MsgBox "No numbers"
Exit Sub
End If

With rng.Offset(0, 1)
.Formula = "=" & rng(1).Address(0, 0) & "/max(" & rng.Address & ")"

myValue = .Value
If CLng(myValue) * 100 = myValue * 100 Then
myNumberFormat = "0%"
Else
myNumberFormat = "0.#%"
End If

.HorizontalAlignment = xlCenter
.NumberFormat = myNumberFormat
End With

End Sub




Wazooli wrote:

I need to fit it into the existing code I have:

Sub Btn_click()
Dim rng As Range
Dim decide As Double

Set rng = Selection

If rng.Areas.count 1 Then Exit Sub
If rng.Columns.count 1 Then Exit Sub
If Application.count(rng) = 0 Or Application.Max(rng) = 0 Then
MsgBox "No numbers"
Exit Sub
End If
With rng.Offset(0, 1)
.Formula = "=" & rng(1).Address(0, 0) & "/max(" & rng.Address & ")"
.HorizontalAlignment = xlCenter
.NumberFormat = "0.#%"
End With

End Sub
(code supplied kindly by Tom O., modified slightly by me)

wazooli

"Dave Peterson" wrote:

Dim myValue as double
dim myNumberFormat as string

myValue = 1.000

if clng(myvalue) * 100 = myvalue * 100 then
mynumberformat = "##0"
else
mynumberformat = "##0.0"
end if



Wazooli wrote:

How can I use the numberformat property as such:

1.000 becomes 100%
0.547 becomes 54.7%

i currently have .numberformat = "0.#%", which gives

1.000 - 100.% (dangling decimal point)
0.547 - 54.7% (correct)

.numberformat = "0.0%" gives
1.000 - 100.0% (dangling zero)
0.547 - 54.7% (correct)

wazooli

--

Dave Peterson


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default getting rid of trailing zeroes

Is this what you want?

For Each cell in rng
.Formula = "=" & cell.Address(0, 0) & "/max(" & cell.Address & ")"

myValue = .Value
If CLng(myValue) * 100 = myValue * 100 Then
myNumberFormat = "0%"
Else
myNumberFormat = "0.0%"
End If

cell.HorizontalAlignment = xlCenter
cell.NumberFormat = myNumberFormat
End With


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Wazooli" wrote in message
...
Doesn't work. I guess what I need to do is extract each cell in the range
individually, and format according to whether there is a trailing zero or
not. The question is...

if rng = selection, how do i get individual cell.value information out?

"Dave Peterson" wrote:

Maybe...

Option Explicit

Sub Btn_click()
Dim rng As Range
Dim decide As Double

Dim myValue As Double
Dim myNumberFormat As String

Set rng = Selection

If rng.Areas.Count 1 Then Exit Sub
If rng.Columns.Count 1 Then Exit Sub
If Application.Count(rng) = 0 Or Application.Max(rng) = 0 Then
MsgBox "No numbers"
Exit Sub
End If

With rng.Offset(0, 1)
.Formula = "=" & rng(1).Address(0, 0) & "/max(" & rng.Address &

")"

myValue = .Value
If CLng(myValue) * 100 = myValue * 100 Then
myNumberFormat = "0%"
Else
myNumberFormat = "0.#%"
End If

.HorizontalAlignment = xlCenter
.NumberFormat = myNumberFormat
End With

End Sub




Wazooli wrote:

I need to fit it into the existing code I have:

Sub Btn_click()
Dim rng As Range
Dim decide As Double

Set rng = Selection

If rng.Areas.count 1 Then Exit Sub
If rng.Columns.count 1 Then Exit Sub
If Application.count(rng) = 0 Or Application.Max(rng) = 0 Then
MsgBox "No numbers"
Exit Sub
End If
With rng.Offset(0, 1)
.Formula = "=" & rng(1).Address(0, 0) & "/max(" & rng.Address &

")"
.HorizontalAlignment = xlCenter
.NumberFormat = "0.#%"
End With

End Sub
(code supplied kindly by Tom O., modified slightly by me)

wazooli

"Dave Peterson" wrote:

Dim myValue as double
dim myNumberFormat as string

myValue = 1.000

if clng(myvalue) * 100 = myvalue * 100 then
mynumberformat = "##0"
else
mynumberformat = "##0.0"
end if



Wazooli wrote:

How can I use the numberformat property as such:

1.000 becomes 100%
0.547 becomes 54.7%

i currently have .numberformat = "0.#%", which gives

1.000 - 100.% (dangling decimal point)
0.547 - 54.7% (correct)

.numberformat = "0.0%" gives
1.000 - 100.0% (dangling zero)
0.547 - 54.7% (correct)

wazooli

--

Dave Peterson


--

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
Include trailing zeroes in calculation AnnieMa Excel Discussion (Misc queries) 0 February 8th 11 12:43 PM
Can I set the default for "show zeroes" to not show the zeroes? jeel Setting up and Configuration of Excel 1 January 25th 08 07:18 PM
eliminating trailing zeroes imported into word document from excel file [email protected] Excel Discussion (Misc queries) 4 June 9th 07 04:08 PM
Sorry, leading zeroes again :-(( Argghhhh Excel Discussion (Misc queries) 7 November 13th 06 10:26 PM
excel .txt to .cvs, lose trailing zeroes in numeric field stevefromatlanta Excel Discussion (Misc queries) 0 January 10th 06 07:01 PM


All times are GMT +1. The time now is 09:32 AM.

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"