Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default Simple Division??

I have a spread sheet. I would like to take it and be able to put a number
in it and have it automatically give me a percentage. In other words column
C has to totals. Lets say C2 is 5 and I type in 1 into D2. Is there a way
to have it automatically change my 1 into 20%? I have to do this for columns
D through R and have it figure out a percentage based off the totals listed
in column C. I don't need to show "1" just the percentage of 1 and 5...
Confusing enough yet? Any help would be most appreciated :)

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Simple Division??

right click on the sheet tab and select view code.

Put in code like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
If Target.Column = 4 Then
v = Target.Offset(0, -1).Value
If IsNumeric(v) And IsNumeric(Target) Then
If v < 0 Then
Application.EnableEvents = False
On Error Resume Next
v1 = CDbl(Target.Value) / CDbl(v)
If Not IsError(v1) Then
Target.Value = v1
Target.NumberFormat = "#.0%"
End If
Application.EnableEvents = True
End If
End If
End If
End Sub


--
Regards,
Tom Ogilvy

"Steve" wrote in message
...
I have a spread sheet. I would like to take it and be able to put a

number
in it and have it automatically give me a percentage. In other words

column
C has to totals. Lets say C2 is 5 and I type in 1 into D2. Is there a

way
to have it automatically change my 1 into 20%? I have to do this for

columns
D through R and have it figure out a percentage based off the totals

listed
in column C. I don't need to show "1" just the percentage of 1 and 5...
Confusing enough yet? Any help would be most appreciated :)



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default Simple Division??

Thanks!

I entered that in, and it doesn't seem to be working. Maybe I'm doing
something wrong. It keeps trying to put all of that program into a cell...
and lists it as information not a function

"Tom Ogilvy" wrote:

right click on the sheet tab and select view code.

Put in code like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
If Target.Column = 4 Then
v = Target.Offset(0, -1).Value
If IsNumeric(v) And IsNumeric(Target) Then
If v < 0 Then
Application.EnableEvents = False
On Error Resume Next
v1 = CDbl(Target.Value) / CDbl(v)
If Not IsError(v1) Then
Target.Value = v1
Target.NumberFormat = "#.0%"
End If
Application.EnableEvents = True
End If
End If
End If
End Sub


--
Regards,
Tom Ogilvy

"Steve" wrote in message
...
I have a spread sheet. I would like to take it and be able to put a

number
in it and have it automatically give me a percentage. In other words

column
C has to totals. Lets say C2 is 5 and I type in 1 into D2. Is there a

way
to have it automatically change my 1 into 20%? I have to do this for

columns
D through R and have it figure out a percentage based off the totals

listed
in column C. I don't need to show "1" just the percentage of 1 and 5...
Confusing enough yet? Any help would be most appreciated :)




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Simple Division??

Give this a whirl

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrorHandler
If Target.Column < 19 And Target.Column 3 And _
IsNumeric(Target.Value) Then
Application.EnableEvents = False
Target.Value = Target.Value / Target.Offset(0, -(Target.Column - 3))
End If

ErrorHandler:
Application.EnableEvents = True
End Sub
--
HTH...

Jim Thomlinson


"Steve" wrote:

I have a spread sheet. I would like to take it and be able to put a number
in it and have it automatically give me a percentage. In other words column
C has to totals. Lets say C2 is 5 and I type in 1 into D2. Is there a way
to have it automatically change my 1 into 20%? I have to do this for columns
D through R and have it figure out a percentage based off the totals listed
in column C. I don't need to show "1" just the percentage of 1 and 5...
Confusing enough yet? Any help would be most appreciated :)

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Simple Division??

The solution that I have given you here is VBA code so you need to put it in
the code behind the sheet. Your macros need to be enabled. (if they are not
select Tools - macros- Security - Medium and then shut down your Excel and
re-open it). Now right click on the Tab of the sheet you want to use this on
and select View Code. Paste this in the code window that opens up and you are
good to go. That is the same procedure to use with Tom's code... I have not
looked at it too closely but Tom is not wrong very often so I would be
willing to guess that it works.
--
HTH...

Jim Thomlinson


"Jim Thomlinson" wrote:

Give this a whirl

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrorHandler
If Target.Column < 19 And Target.Column 3 And _
IsNumeric(Target.Value) Then
Application.EnableEvents = False
Target.Value = Target.Value / Target.Offset(0, -(Target.Column - 3))
End If

ErrorHandler:
Application.EnableEvents = True
End Sub
--
HTH...

Jim Thomlinson


"Steve" wrote:

I have a spread sheet. I would like to take it and be able to put a number
in it and have it automatically give me a percentage. In other words column
C has to totals. Lets say C2 is 5 and I type in 1 into D2. Is there a way
to have it automatically change my 1 into 20%? I have to do this for columns
D through R and have it figure out a percentage based off the totals listed
in column C. I don't need to show "1" just the percentage of 1 and 5...
Confusing enough yet? Any help would be most appreciated :)



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Simple Division??

It doesn't go in a cell. As I said, right click on the sheet tab and select
view code.

a module will appear. Paste the code in that, then return to excel. It is
set up to only work with entries made in column D.

--
Regards,
Tom Ogilvy


"Steve" wrote in message
...
Thanks!

I entered that in, and it doesn't seem to be working. Maybe I'm doing
something wrong. It keeps trying to put all of that program into a

cell...
and lists it as information not a function

"Tom Ogilvy" wrote:

right click on the sheet tab and select view code.

Put in code like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
If Target.Column = 4 Then
v = Target.Offset(0, -1).Value
If IsNumeric(v) And IsNumeric(Target) Then
If v < 0 Then
Application.EnableEvents = False
On Error Resume Next
v1 = CDbl(Target.Value) / CDbl(v)
If Not IsError(v1) Then
Target.Value = v1
Target.NumberFormat = "#.0%"
End If
Application.EnableEvents = True
End If
End If
End If
End Sub


--
Regards,
Tom Ogilvy

"Steve" wrote in message
...
I have a spread sheet. I would like to take it and be able to put a

number
in it and have it automatically give me a percentage. In other words

column
C has to totals. Lets say C2 is 5 and I type in 1 into D2. Is there

a
way
to have it automatically change my 1 into 20%? I have to do this for

columns
D through R and have it figure out a percentage based off the totals

listed
in column C. I don't need to show "1" just the percentage of 1 and

5...
Confusing enough yet? Any help would be most appreciated :)






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
Division linda.davis20 Excel Discussion (Misc queries) 2 March 31st 09 07:41 PM
Simple Division Maurice New Users to Excel 1 October 10th 07 01:20 AM
Division EK Excel Worksheet Functions 2 May 3rd 07 04:05 PM
HOW DO I DO SIMPLE DIVISION? confused in california Excel Worksheet Functions 2 February 1st 06 03:17 AM
How do you create formulas in pivot table eg simple division? Belinda_Tim Excel Worksheet Functions 2 January 5th 06 03:03 PM


All times are GMT +1. The time now is 10:22 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"