|
-
Apr 21st, 2005, 08:30 PM
#1
Excel - Change cell formula from nested IFs to ??
So I have this ugly formula on a bunch of rows that looks like...
Code:
= (H23*IF(D23="YT",0.39,IF(D23="M/C",0.4,IF(D23="KK",0.45,IF(D23="M",0.71,0)))))
and I want to use VBA and change it over to a Select Case type of thing. I've never really worked with VBA before. What event(s) would I used, and so forth? Who wants to help me out? I'll send you five teeth for your trouble.
Last edited by crptcblade; Apr 22nd, 2005 at 07:24 AM.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Apr 21st, 2005, 11:29 PM
#2
Re: Excel - Change cell formula from nested IFs to ??
I need more info on what type of event you need to call this from. so I just made it a public function that can be
called from any sheet or event. Place it in a Module and we shall see where it needs to be called from best.
VB Code:
Public Function crptcblade() As Double
Dim dblValue As Double
Select Case D23
Case "YT"
dblValue = 0.39
Case "M/C"
dblValue = 0.4
Case "KK"
dblValue = 0.45
Case "M"
dblValue = 0.71
Case Else
dblValue = 0
End Select
'H23 equals - Workbooks("Book1").Sheets("Sheet1").Cells(23, 8).Value
crptcblade = Workbooks("Book1").Sheets("Sheet1").Cells(23, 8).Value * dblValue
End Function
When can I expect my 5 teeth? Are they molars or fangs? 
Edit: Dont you mean 7 teeth?
Last edited by RobDog888; Apr 21st, 2005 at 11:40 PM.
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 
-
Apr 22nd, 2005, 04:18 AM
#3
Re: Excel - Change cell formula from nested IFs to ??
 Originally Posted by RobDog888
I need more info on what type of event you need to call this from.
It would need to be a replacement for a formula in a range of cells. Basically, each cell in column K has that formula in it, but new values will be getting added regularly, and I don't want to have to maintain that big IF statement.
The only event I found was Sheet_Calculate, but I don't know how to figure out which cell has changed in order to update it.
As for the teeth, please transfer $458 for s/h to my Paypal and they are as good as yours.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Apr 22nd, 2005, 07:26 AM
#4
Re: Excel - Change cell formula from nested IFs to ??
Resolved by me. I figured out how to link a function in a module to the formula.
So I'll keep the teeth.
:evil:
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Apr 22nd, 2005, 07:40 AM
#5
Addicted Member
Re: Excel - Change cell formula from nested IFs to ??
hi,
can you post how you achieved the resolution?
I would be interested to know.
Thnx
if you fail to plan, you plan to fail
-
Apr 22nd, 2005, 10:19 AM
#6
Re: Excel - Change cell formula from nested IFs to ??
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 
-
Apr 22nd, 2005, 07:01 PM
#7
Re: Excel - Change cell formula from nested IFs to ??
 Originally Posted by Br1an_g
hi,
can you post how you achieved the resolution?
I would be interested to know.
Thnx 
It actually turned out to be pretty easy. Add a module, and make a public function.
Code:
Public Function ReturnSomeValue(CellValue) As Double
ReturnSomeValue = Val(CellValue) * 2.24
End Function
Then make the formula in the cell "=ReturnSomeValue(H4)" and it should work fine. I guess it gets a little hinky passing ranges of cells in, I only needed to worry about one cell at a time.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
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
|