LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default need help writing normalize function

Thanks Tom - works great, and thanks to John Walkenbach, it couldn't be
easier to attach it to a toolbar. Thanks again.

wazooli

"Tom Ogilvy" wrote:

I put sum and it should have been max:


rng.Offset(0, 1).Formula = "=" & _
rng(1).Address(0, 0) & _
"/MAX(" & rng.Address & ")"

--
Regards,
Tom Ogilvy


"Tom Ogilvy" wrote in message
...
The basic code could be as simple as:

Sub Btn_click()
set rng = Selection
rng.Offset(0, 1).Formula = "=" & _
rng(1).Address(0, 0) & _
"/SUM(" & rng.Address & ")"
rng.Offset(0, 1).NumberFormat = "0.00%"
End Sub

but you might want to do some checking.

Sub Btn_click()
Dim rng As Range
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
rng.Offset(0, 1).Formula = "=" & _
rng(1).Address(0, 0) & _
"/SUM(" & rng.Address & ")"
rng.Offset(0, 1).NumberFormat = "0.00%"
End Sub

--
Regards,
Tom Ogilvy


"Wazooli" wrote in message
...
I know how to do this using worksheet functions. The point of this

exercise
is to try and teach myself how to do something simple in VBA. I would
eventually like to assign a menu button to this function, so I can

simply
select the areas, hit the button, and the values get filled in for me.

wazooli

"Steve" wrote:

Wazooli

It looks to me that you are trying to fnd a percentage of the total of

each
value entered into column A and that the result should change if more

data
are entered into column A.
This will work provided column A contains raw data only (eg do not

perform a
sum of column A values within column A)

=IF(ISBLANK(A1),"",(A1/SUM(A:A)))

Enter it at B1.
Drag or copy down as far as you like.
Format column B as a percentage

HTH
Steve

"Wazooli" wrote in message
...
I am having trouble writing a normalization function. Basically, I

would
like to choose 2 ranges, the first with values, and the second to

have
normalized values filled in. If my first range is A1:A20, the

formula
should
be (placed in B1):

=A1/max(A$1:A$20)

, and filled from B1:B20.

I would like this function to be flexible in terms of the size of

the
ranges, with equal size for both being mandatory. In the end, I

would
like
the values to be converted into %s.

wazooli








 
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
need help writing function LQQKB4uleep Excel Worksheet Functions 9 November 20th 09 12:30 AM
Function writing help Gator Excel Worksheet Functions 2 March 2nd 09 05:51 PM
WRITING A WHAT IF FUNCTION MARY Excel Worksheet Functions 1 June 13th 08 12:36 PM
Normalize Frank Excel Worksheet Functions 6 November 23rd 06 08:24 PM
writing its own function AG[_4_] Excel Programming 8 September 30th 03 02:06 PM


All times are GMT +1. The time now is 03:48 PM.

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"