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

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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