Hi members
i have managed to incorporate a dollar commision and a percentage commision to the formula.(a little messy though)
previous post was
http://www.mrexcel.com/board/viewtopic.php?topic=24440&forum=2&
now i have a problem as it only shows the whole numbers, If i use round( statement,4) it doesnt show the 4 digits after the decimal.
does an iif statement cancel the decimal digits.
Option Explicit
Sub profit()
Dim RowNo As Long
Dim FirstCell As Range
Dim commdollar As Variant
Dim commpercent As Variant
Dim buyValue As Variant
Dim sellvalue As Variant
Dim buyCell As Range
Dim sellCell As Range
Dim newstartcapvalue2 As Variant
Dim startcap As Variant
Dim totalprofit As Variant
Dim profitonly As Variant
Dim numshares As Variant
' Dim remainder As Variant
commdollar = Application.InputBox("Enter dollar value of commision:", _
, 0, , , , , 1)
commpercent = Application.InputBox("Enter percentage of commision:", _
, 0, , , , , 1)
Application.ScreenUpdating = False
Set FirstCell = Application.Range("a2")
' Range("M1").Select
' ActiveCell.FormulaR1C1 = " remainder..."
' Cells.EntireColumn.AutoFit
Range("L1").Select
ActiveCell.FormulaR1C1 = " num of shares...."
Cells.EntireColumn.AutoFit
Range("K1").Select
ActiveCell.FormulaR1C1 = " profit........."
Cells.EntireColumn.AutoFit
Range("J1").Select
ActiveCell.FormulaR1C1 = " totalprofit...."
Cells.EntireColumn.AutoFit
Range("I1").Select
ActiveCell.FormulaR1C1 = " startcapital...."
Cells.EntireColumn.AutoFit
startcap = 10000
RowNo = 1
Do
If IsEmpty(FirstCell.Cells(RowNo, 1)) Then Exit Do
' Value in Column E
buyValue = FirstCell.Cells(RowNo, 5)
' Value in Column F
sellvalue = FirstCell.Cells(RowNo, 6)
' Column i
Set buyCell = FirstCell.Cells(RowNo, 9)
' Column j
Set sellCell = FirstCell.Cells(RowNo, 10)
buyCell.Value = IIf(commpercent > 0, startcap - Round(((startcap / 100) * commpercent), 4), 0) _
Or IIf(commdollar > 0, startcap - commdollar, 0)
'startcap -commision
'sellCell.Value = Round((((startcap - commision) / buyValue)) * sellvalue - commision, 4)
sellCell.Value = IIf(commpercent > 0, Round((((startcap - (((startcap / 100) * commpercent))) / buyValue)) * _
sellvalue - (((((startcap - (((startcap / 100) * commpercent))) / buyValue)) * _
sellvalue) / 100) * commpercent, 4), 0) Or _
IIf(commdollar > 0, Round((((startcap - commdollar) / buyValue)) * sellvalue - commdollar, 4), 0)
startcap = sellCell.Value
RowNo = RowNo + 1
Loop
Set FirstCell = Range("A2")
newstartcapvalue2 = 10000
RowNo = 1
Do
If IsEmpty(FirstCell.Cells(RowNo, 1)) Then Exit Do
startcap = FirstCell.Cells(RowNo, 9)
totalprofit = FirstCell.Cells(RowNo, 10)
Set profitonly = FirstCell.Cells(RowNo, 11)
profitonly.Value = IIf(commpercent > 0, Round((totalprofit - startcap - ((startcap / 100) * _
commpercent)), 4), 0) Or _
IIf(commdollar > 0, Round(totalprofit - startcap - commdollar, 4), 0)
RowNo = RowNo + 1
Loop
Set FirstCell = Range("A2")
RowNo = 1
Do
If IsEmpty(FirstCell.Cells(RowNo, 1)) Then Exit Do
startcap = FirstCell.Cells(RowNo, 9)
buyValue = FirstCell.Cells(RowNo, 5)
Set numshares = FirstCell.Cells(RowNo, 12)
numshares.Value = Round((startcap / buyValue), 4)
'Set remainder = FirstCell.Cells(RowNo, 13)
'remainder.Value = Round((startcap / buyValue) - Int((startcap / buyValue)), 4)
RowNo = RowNo + 1
Loop
Application.ScreenUpdating = True
End Sub
thanks
mike.
i have managed to incorporate a dollar commision and a percentage commision to the formula.(a little messy though)
previous post was
http://www.mrexcel.com/board/viewtopic.php?topic=24440&forum=2&
now i have a problem as it only shows the whole numbers, If i use round( statement,4) it doesnt show the 4 digits after the decimal.
does an iif statement cancel the decimal digits.
Option Explicit
Sub profit()
Dim RowNo As Long
Dim FirstCell As Range
Dim commdollar As Variant
Dim commpercent As Variant
Dim buyValue As Variant
Dim sellvalue As Variant
Dim buyCell As Range
Dim sellCell As Range
Dim newstartcapvalue2 As Variant
Dim startcap As Variant
Dim totalprofit As Variant
Dim profitonly As Variant
Dim numshares As Variant
' Dim remainder As Variant
commdollar = Application.InputBox("Enter dollar value of commision:", _
, 0, , , , , 1)
commpercent = Application.InputBox("Enter percentage of commision:", _
, 0, , , , , 1)
Application.ScreenUpdating = False
Set FirstCell = Application.Range("a2")
' Range("M1").Select
' ActiveCell.FormulaR1C1 = " remainder..."
' Cells.EntireColumn.AutoFit
Range("L1").Select
ActiveCell.FormulaR1C1 = " num of shares...."
Cells.EntireColumn.AutoFit
Range("K1").Select
ActiveCell.FormulaR1C1 = " profit........."
Cells.EntireColumn.AutoFit
Range("J1").Select
ActiveCell.FormulaR1C1 = " totalprofit...."
Cells.EntireColumn.AutoFit
Range("I1").Select
ActiveCell.FormulaR1C1 = " startcapital...."
Cells.EntireColumn.AutoFit
startcap = 10000
RowNo = 1
Do
If IsEmpty(FirstCell.Cells(RowNo, 1)) Then Exit Do
' Value in Column E
buyValue = FirstCell.Cells(RowNo, 5)
' Value in Column F
sellvalue = FirstCell.Cells(RowNo, 6)
' Column i
Set buyCell = FirstCell.Cells(RowNo, 9)
' Column j
Set sellCell = FirstCell.Cells(RowNo, 10)
buyCell.Value = IIf(commpercent > 0, startcap - Round(((startcap / 100) * commpercent), 4), 0) _
Or IIf(commdollar > 0, startcap - commdollar, 0)
'startcap -commision
'sellCell.Value = Round((((startcap - commision) / buyValue)) * sellvalue - commision, 4)
sellCell.Value = IIf(commpercent > 0, Round((((startcap - (((startcap / 100) * commpercent))) / buyValue)) * _
sellvalue - (((((startcap - (((startcap / 100) * commpercent))) / buyValue)) * _
sellvalue) / 100) * commpercent, 4), 0) Or _
IIf(commdollar > 0, Round((((startcap - commdollar) / buyValue)) * sellvalue - commdollar, 4), 0)
startcap = sellCell.Value
RowNo = RowNo + 1
Loop
Set FirstCell = Range("A2")
newstartcapvalue2 = 10000
RowNo = 1
Do
If IsEmpty(FirstCell.Cells(RowNo, 1)) Then Exit Do
startcap = FirstCell.Cells(RowNo, 9)
totalprofit = FirstCell.Cells(RowNo, 10)
Set profitonly = FirstCell.Cells(RowNo, 11)
profitonly.Value = IIf(commpercent > 0, Round((totalprofit - startcap - ((startcap / 100) * _
commpercent)), 4), 0) Or _
IIf(commdollar > 0, Round(totalprofit - startcap - commdollar, 4), 0)
RowNo = RowNo + 1
Loop
Set FirstCell = Range("A2")
RowNo = 1
Do
If IsEmpty(FirstCell.Cells(RowNo, 1)) Then Exit Do
startcap = FirstCell.Cells(RowNo, 9)
buyValue = FirstCell.Cells(RowNo, 5)
Set numshares = FirstCell.Cells(RowNo, 12)
numshares.Value = Round((startcap / buyValue), 4)
'Set remainder = FirstCell.Cells(RowNo, 13)
'remainder.Value = Round((startcap / buyValue) - Int((startcap / buyValue)), 4)
RowNo = RowNo + 1
Loop
Application.ScreenUpdating = True
End Sub
thanks
mike.