J
jacob farino
Hi,
I have three cells. The first is loan amount, one is % and one is Dollars.
I'd like to be able to enter the second (i.e. "3%") and have it multiply the
first to display dollars in the dollars cell:
loan amount $10,000 x 3% = $___
OR
I want to be able to enter dollars and have it divide into a percent:
loan amount $10,000 (/) $300 = 3%.
Let's label the cells A1, B1, C1.
So A1 is loan amount, B1 is %, and C1 is $$$
Obviously, without a macro, it will erase a formula if I enter it into any
of these cells. Below is a sample macro I got from a person for another
function, but I can't translate it to what I need.
HELP!!!
}jacob{
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Sales As Range
Dim CommissionDollar As Range
Dim CommissionPercent As Range
Dim YSPDollar As Range
Dim YSPpercent As Range
Dim RowIndex As Integer
Dim Msg As String
Set Sales = [H7:H65000]
Set CommissionDollar = [I7:I65000]
Set CommissionPercent = [J7:J65000]
Set YSPDollar = [K7:K65000]
Set YSPpercent = [L7:L65000]
If Target.Count > 1 Then Exit Sub
Application.EnableEvents = False
RowIndex = Target.Row - Sales.Row + 1
On Error GoTo ErrorHandler
If Not Intersect(Target, CommissionDollar) Is Nothing Then
CommissionPercent(RowIndex, 1) = Target / Sales(RowIndex, 1)
ElseIf Not Intersect(Target, CommissionPercent) Is Nothing Then
CommissionDollar(RowIndex, 1) = Target * Sales(RowIndex, 1)
ElseIf Not Intersect(Target, YSPDollar) Is Nothing Then
YSPpercent(RowIndex, 1) = Target / Sales(RowIndex, 1)
ElseIf Not Intersect(Target, YSPpercent) Is Nothing Then
YSPDollar(RowIndex, 1) = Target * Sales(RowIndex, 1)
ElseIf Not Intersect(Target, Sales) Is Nothing Then
If Target.Value = 0 Then
CommissionPercent(RowIndex, 1).ClearContents
CommissionDollar(RowIndex, 1).ClearContents
ElseIf CommissionDollar(RowIndex, 1) <> 0 Then
CommissionPercent(RowIndex, 1) = CommissionDollar(RowIndex, 1) /
Target
ElseIf CommissionPercent(RowIndex, 1) <> 0 Then
CommissionDollar(RowIndex, 1) = Target * CommissionPercent(RowIndex,
1)
End If
If Target.Value = 0 Then
YSPpercent(RowIndex, 1).ClearContents
YSPDollar(RowIndex, 1).ClearContents
ElseIf YSPDollar(RowIndex, 1) <> 0 Then
YSPpercent(RowIndex, 1) = YSPDollar(RowIndex, 1) / Target
ElseIf YSPpercent(RowIndex, 1) <> 0 Then
YSPDollar(RowIndex, 1) = Target * YSPpercent(RowIndex, 1)
End If
End If
Application.EnableEvents = True
Exit Sub
ErrorHandler:
'Msg = "Error # " & Str(Err.Number) & " was generated by " _
& Err.Source & Chr(13) & Err.Description
'MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext
MsgBox ("Data Entry Error")
Application.EnableEvents = True
End Sub
I have three cells. The first is loan amount, one is % and one is Dollars.
I'd like to be able to enter the second (i.e. "3%") and have it multiply the
first to display dollars in the dollars cell:
loan amount $10,000 x 3% = $___
OR
I want to be able to enter dollars and have it divide into a percent:
loan amount $10,000 (/) $300 = 3%.
Let's label the cells A1, B1, C1.
So A1 is loan amount, B1 is %, and C1 is $$$
Obviously, without a macro, it will erase a formula if I enter it into any
of these cells. Below is a sample macro I got from a person for another
function, but I can't translate it to what I need.
HELP!!!
}jacob{
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Sales As Range
Dim CommissionDollar As Range
Dim CommissionPercent As Range
Dim YSPDollar As Range
Dim YSPpercent As Range
Dim RowIndex As Integer
Dim Msg As String
Set Sales = [H7:H65000]
Set CommissionDollar = [I7:I65000]
Set CommissionPercent = [J7:J65000]
Set YSPDollar = [K7:K65000]
Set YSPpercent = [L7:L65000]
If Target.Count > 1 Then Exit Sub
Application.EnableEvents = False
RowIndex = Target.Row - Sales.Row + 1
On Error GoTo ErrorHandler
If Not Intersect(Target, CommissionDollar) Is Nothing Then
CommissionPercent(RowIndex, 1) = Target / Sales(RowIndex, 1)
ElseIf Not Intersect(Target, CommissionPercent) Is Nothing Then
CommissionDollar(RowIndex, 1) = Target * Sales(RowIndex, 1)
ElseIf Not Intersect(Target, YSPDollar) Is Nothing Then
YSPpercent(RowIndex, 1) = Target / Sales(RowIndex, 1)
ElseIf Not Intersect(Target, YSPpercent) Is Nothing Then
YSPDollar(RowIndex, 1) = Target * Sales(RowIndex, 1)
ElseIf Not Intersect(Target, Sales) Is Nothing Then
If Target.Value = 0 Then
CommissionPercent(RowIndex, 1).ClearContents
CommissionDollar(RowIndex, 1).ClearContents
ElseIf CommissionDollar(RowIndex, 1) <> 0 Then
CommissionPercent(RowIndex, 1) = CommissionDollar(RowIndex, 1) /
Target
ElseIf CommissionPercent(RowIndex, 1) <> 0 Then
CommissionDollar(RowIndex, 1) = Target * CommissionPercent(RowIndex,
1)
End If
If Target.Value = 0 Then
YSPpercent(RowIndex, 1).ClearContents
YSPDollar(RowIndex, 1).ClearContents
ElseIf YSPDollar(RowIndex, 1) <> 0 Then
YSPpercent(RowIndex, 1) = YSPDollar(RowIndex, 1) / Target
ElseIf YSPpercent(RowIndex, 1) <> 0 Then
YSPDollar(RowIndex, 1) = Target * YSPpercent(RowIndex, 1)
End If
End If
Application.EnableEvents = True
Exit Sub
ErrorHandler:
'Msg = "Error # " & Str(Err.Number) & " was generated by " _
& Err.Source & Chr(13) & Err.Description
'MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext
MsgBox ("Data Entry Error")
Application.EnableEvents = True
End Sub