VBA Count if function ("<")

anusa

New Member
Joined
Aug 11, 2015
Messages
4
Hello, I am new to VBA.

I have the following code

Sub Backtest()


Dim myRange As Range
Dim a As Long
Dim i As Long, j As Long

Set myRange = Range("b3:b217")

For i = 1 To myRange.Rows.Count

Worksheets("backtesting").Range("b" & i + 2).Copy
Worksheets("izberi datum").Range("E3").PasteSpecial xlPasteValues

Worksheets("backtesting").Range("C" & i + 2) = Worksheets("var in mvar").Range("g12") * Worksheets("var in mvar").Range("j14")
a = Worksheets("backtesting").Range("C" & i + 2)
Worksheets("backtesting").Range("D" & i + 2) = Application.CountIf(Worksheets("donos_portfelja").Range("am4:am265"), "<" & a)

Next i

End Sub


My Count if function is not working. I receieve numbers but they are wrong. Is is possible there is a problem with decimals as the number a is around -0,008?
If I type in the number it works!
Thank you for your help...

Ana
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Forum statistics

Threads
1,214,959
Messages
6,122,476
Members
449,087
Latest member
RExcelSearch

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