solved a problem now i cant get values after a decimal

excelent

Board Regular
Joined
Sep 7, 2002
Messages
105
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.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Similar threads

Forum statistics

Threads
1,224,802
Messages
6,181,053
Members
453,014
Latest member
Chris258

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top