Hi,
I need help to toggle between % or $ down payment. I can input % then calculate the % of a loan.
When I click $ option button, I want the $value to switch in the first row, % in second row.
Thanks
Hi,
I need help to toggle between % or $ down payment. I can input % then calculate the % of a loan.
When I click $ option button, I want the $value to switch in the first row, % in second row.
Thanks
Last edited by Rocky2013; 03-09-2015 at 09:30 PM.
See attached
The result is not is not exactly what I need.
1. If I click % option button,
D7 I enter 5.00%,
D9 will show a calculated value $1000.
2. If I click $ option button,
D7 will automatically change from % value/unit to $1,000,
D9 will atomatically change to 5.00%.
The steps are the same if $ button is first picked, $1000 will type in D7 , 5% will show in D9.
Click % button, then D7 will show 5.00%, D9 will show $1,000. Basicly D7 and D9 incliding
the unit symbols switch back and fore.
Hopefully I explain it right.
Last edited by Rocky2013; 03-09-2015 at 08:06 AM.
Hello
Check attached
I am new to vba
Sorry if this was not what you required...
Happy to Help
How to upload excel workbooks at this forum - http://www.excelforum.com/the-water-...his-forum.html
"I don't get things easily, so please be precise and elaborate"
If someone's post has helped you, thank by clicking on "Add Reputation" below the post.
If your query is resolved please mark the thread as "Solved" from the "Thread Tools" above.
Sourabh
Thanks, it works but there is a pop-up message ....
Run-time error '1004';
Method 'Range' of objects'_Globe' failede.
If you are new in VBA, I am just an infant. Please advise if you can eliminate the pop-up
or welcome who may offer help.
Thanks all!
Last edited by Rocky2013; 03-09-2015 at 08:37 PM.
Here's my effort, you'll have to change the locations for rngBaseValue, modeCell and otherCell to match your worksheet.
I've reworked the display a bit in my attachment.
![]()
Sub test() Dim CurrentMode As String Dim NewMode As String Dim rngBaseValue As Range Dim modeCell As Range, otherCell As Range Dim Dollars As Double, Percent As Double Const DollarFormat As String = "$ #,##0" Const PctFormat As String = "#.00 %" Set rngBaseValue = Sheet1.Range("A1") Set modeCell = Sheet1.Range("A3") Set otherCell = Sheet1.Range("A5") If modeCell.NumberFormat = DollarFormat Then CurrentMode = "dollar" Else CurrentMode = "percent" End If If ActiveSheet.Shapes("Option Button 1").ControlFormat.Value = xlOn Then NewMode = "percent" Else NewMode = "dollar" End If If CurrentMode <> NewMode Then If CurrentMode = "dollar" Then Dollars = modeCell.Value Percent = Dollars / Val(CStr(rngBaseValue.Value)) Else Percent = modeCell.Value Dollars = Val(CStr(rngBaseValue.Value)) End If If NewMode = "dollar" Then With modeCell .NumberFormat = DollarFormat .Value = Dollars End With With otherCell .NumberFormat = PctFormat .Formula = "=" & modeCell.Address & "/" & rngBaseValue.Address End With Else With modeCell .NumberFormat = PctFormat .Value = Percent End With With otherCell .NumberFormat = DollarFormat .Formula = "=" & modeCell.Address & "*" & rngBaseValue.Address End With End If End If End Sub
_
...How to Cross-post politely...
..Wrap code by selecting the code and clicking the # or read this. Thank you.
Hi surabhg98
Foe some reason, wen I saved the file then reopen, the error message did not pop-up. It works now. Thanks
Hi Mike,
Thanks for the quick replay of your effort to help. I have to play around with your code.
Thanks both again!
I just noticed an error.
Line 32 needs to be changed.
![]()
Sub test() Dim CurrentMode As String Dim NewMode As String Dim rngBaseValue As Range Dim modeCell As Range, otherCell As Range Dim Dollars As Double, Percent As Double Const DollarFormat As String = "$ #,##0" Const PctFormat As String = "#.00 %" Set rngBaseValue = Sheet1.Range("A1") Set modeCell = Sheet1.Range("A3") Set otherCell = Sheet1.Range("A5") If modeCell.NumberFormat = DollarFormat Then CurrentMode = "dollar" Else CurrentMode = "percent" End If If ActiveSheet.Shapes("Option Button 1").ControlFormat.Value = xlOn Then NewMode = "percent" Else NewMode = "dollar" End If If CurrentMode <> NewMode Then If CurrentMode = "dollar" Then Dollars = modeCell.Value Percent = Dollars / Val(CStr(rngBaseValue.Value)) Else Percent = modeCell.Value Dollars = Val(CStr(rngBaseValue.Value)) * Percent: Rem change this <<<<<<<<<<<<<<<<<< End If If NewMode = "dollar" Then With modeCell .NumberFormat = DollarFormat .Value = Dollars End With With otherCell .NumberFormat = PctFormat .Formula = "=" & modeCell.Address & "/" & rngBaseValue.Address End With Else: Rem newmode = "percent" With modeCell .NumberFormat = PctFormat .Value = Percent End With With otherCell .NumberFormat = DollarFormat .Formula = "=" & modeCell.Address & "*" & rngBaseValue.Address End With End If End If End Sub
Alternately, you could use the Change event so that there's no need to toggle.
In the attached, on Sheet2, C1 is the base amount. If the user enters dollars in C3 or percentages in C5, the other will adjust its value.
![]()
' in sheet's code module Private Sub Worksheet_Change(ByVal Target As Range) Dim rngBaseCell As Range Dim dollarCell As Range, percentCell As Range Set rngBaseCell = Range("C1") Set dollarCell = Range("C3") Set percentCell = Range("C5") If Not Application.Intersect(Target, rngBaseCell) Is Nothing Then Application.EnableEvents = False percentCell.Value = Val(CStr(dollarCell.Value)) / Val(CStr(rngBaseCell.Value)) End If If Not Application.Intersect(Target, dollarCell) Is Nothing Then Application.EnableEvents = False percentCell.Value = Val(CStr(dollarCell.Value)) / Val(CStr(rngBaseCell.Value)) End If If Not Application.Intersect(Target, percentCell) Is Nothing Then Application.EnableEvents = False dollarCell.Value = Val(CStr(percentCell.Value)) * Val(CStr(rngBaseCell.Value)) End If Application.EnableEvents = True End Sub
Hi Mike,
Thanks you.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks