|
-
Jun 19th, 2005, 10:16 PM
#1
Excel Formula Question
If I enter 1 in column A I'd like column B to increase by $20.50.
If I enter 2 in column A I'd like column B to increase by $9.70
If I enter 3 in column A I'd like column B to increase by $4.30
If I enter anything else in column A I'd like column B to decrease by $6.50
I assume I can't do that with a simple formula so how would I go about it?
-
Jun 20th, 2005, 12:15 AM
#2
Re: Excel Formula Question
You can do it with a complex nested If formula or some VBA code. Which would you prefer?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 20th, 2005, 12:49 AM
#3
Re: Excel Formula Question
i did some code for it
VB Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
Dim rn As Range
myr = Target.Row: myc = Target.Column + 1
Set rn = Me.Cells(myr, myc)
Select Case Target.Value
Case 1: myval = 20.5
Case 2: myval = 9.7
Case 3: myval = 4.3
Case Else: myval = -6.5
End Select
rn.Value = rn.Value + myval
Set rn = Nothing
End If
End Sub
but i never figured out how to be able to include a cells value in it's formula, a
pete
-
Jun 20th, 2005, 03:56 AM
#4
Re: Excel Formula Question
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Jun 20th, 2005, 08:01 AM
#5
Frenzied Member
Re: Excel Formula Question
Marty ...
If you haven't discovered it already, if you put your conditional calculation in a formula, you are going to bump up the "value in column B" EVERY TIME a recalculation is done. To check this out, hit <F9> a few times and see what happens. I would guess that you do NOT want that to happen. If you only want the action to occur 1 time it will take a VBA program, or you might want to think about adding a control to your worksheet.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Jun 20th, 2005, 08:55 AM
#6
Re: Excel Formula Question
[/QUOTE]If you only want the action to occur 1 time it will take a VBA program, or you might want to think about adding a control to your worksheet.[QUOTE]
the code i posted only changes it once, untill you edit the code in column A
pete
-
Jun 20th, 2005, 09:50 AM
#7
Frenzied Member
Re: Excel Formula Question
I'm guessing that it actually could be done in a formula in the worksheet cell, but it would be a hairy formula! Use the background color or text color as a flag in a complex IF chain ...
Which brings up the thought:
Does anyone know how to run a macro from a formula? There is a "CALL" function for external functions, but I couldn't get it to run a Macro ... sort of like the following:
=IF(logical_test, "Run Macro1", "Run Macro2")
Thanks for any and all comments, suggestions, and assistance.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Jun 20th, 2005, 10:28 AM
#8
Frenzied Member
Re: Excel Formula Question
Marty ... are you still around?
It would be 'expensive' in processing time for a very large worksheet ... but if you really want to do it, here are some additional comments on Pete's approach:
In the Project Explorer, in "ThisWorkbook" module create a Public (Global) boolean flag (or an array of flags) and Initialize it, say to "False", in the Event handler "Private Sub Workbook_Open".
In the "Sheet" Module for the appropriate sheet, set up the Worksheet_Change event handler function. Everytime something on the sheet changes, the following code will run:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'TEST TEST TEST TEST
MsgBox("What changed? " & Target.Address) 'Show 'Target' operation
'END TEST
If Not myFlag Then
If Range("A1").Value > 0 Then
'Put your conditional calculations here
MsgBox ("Sheet Changed and A1 is Greater Than ZERO")
myFlag = True
End If
End If
End Sub
This is just a simple 'proof of concept' prototype to show that it can be done automatically ... without requiring the user to run a Macro ... if you really want to do it. It would get kind of hairy if you want to be able to "Undo" changes to your 'causal' variables. If you get stuck, I can get more explicit ...
Last edited by Webtest; Jun 20th, 2005 at 10:44 AM.
Reason: clarification - Credit to Pete; Added Target Test
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Jun 20th, 2005, 10:58 AM
#9
Re: Excel Formula Question
 Originally Posted by Ecniv
Thanks, I didn't know you could do nesting in a formula. I put the following in column B (row 18). I changed the -6.5 part and it works.
=IF(A18=1,B17+20.5,IF(A18=2,B17+9.7,IF(A18=3,B17+4.3,B17-6.5)))
-
Jun 20th, 2005, 11:06 AM
#10
Re: Excel Formula Question
You guys are up early. 
I didnt post any code last night because of the reasons posted. If you dont want the values to keep incrementing everytime any value is
changed then a second column will be needed.
Kind of like a 'Rate' range or sheet. Then in your formula for column 2 or "B" you can do something like this in the Formula bar...
VB Code:
Column A:
1,2,3 or ?
Column B:
Your numeric value
50 for ex.
Column C Formula:
=IF(A1=1,20.5,IF(A1=2,9.7,IF(A1=3,4.3,-6.5)))
Column D Formula:
=SUM(B3+C3)
Column A | Column B | Column C | Column D
3 50 4.3 54.3
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 20th, 2005, 11:24 AM
#11
Re: Excel Formula Question
the routine i posted is in the code window for sheet1, in the worksheet change event, no other handlers or boolean were needed, for it to run each time a cell in column A was changed, any value in column B was incremented appropriately,
which was what was originally asked for, going back to a cell in column A would only increment it again if it was edited
but i understand now that it was the total value of column b you wanted to increment
pete
-
Jun 20th, 2005, 11:30 AM
#12
Re: Excel Formula Question
Yes I know it wasnt requested but I was reading between the lines. 
Logically there would not be too much use for a condition where a value changes each time the rate value is changed. What if you made
a mistake in entering in a rate? Entered 1 and the value, say 50, was incremented by 20.50 to equal 70.50, but then you correct it to 2
and the value is incremented again to 80.20. Now the correct result without the mistake should be 59.70.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 20th, 2005, 11:33 AM
#13
Re: Excel Formula Question
 Originally Posted by westconn1
...but i understand now that it was the total value of column b you wanted to increment
pete
That's correct. Sorry I wasn't clear.
-
Jun 20th, 2005, 11:40 AM
#14
Re: Excel Formula Question
-
Jun 20th, 2005, 11:43 AM
#15
Frenzied Member
Re: Excel Formula Question
Pete ... Your lead was GREAT! I just added the boolean as a tool to play with in situations like RobDog and I pointed out ... the "Oops!" case ... where you might want to go back and change a previously set value in Column A. It was just a quick exploration.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Jun 20th, 2005, 12:00 PM
#16
Frenzied Member
Re: Excel Formula Question
Martin:
Another way to do this is to use the VLOOKUP function. Just make a table:
1 20.50
2 9.70
3 4.30
4 -6.50
If the range of this array is say D1:E4 then in cell B1:
=VLOOKUP(A1,$D$1:$E$4,2,TRUE)
Now it is trivial to change the rewards table. Just a thought.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Jun 20th, 2005, 12:09 PM
#17
Re: Excel Formula Question
Art, the VLOOKUP using the additional range is the same logic as I suggested in adding a colum for the 'Rate'. Either
one will work well.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 6th, 2005, 10:40 AM
#18
New Member
Re: Excel Formula Question
Use hidden columns and base your formulas on those hidden amounts. Or use the "scenario" function of Excel
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|