VBA Countif less than specific time

30percent

Board Regular
Joined
May 5, 2011
Messages
101
Hi,

I have the following formula on a cell and it gives me number 78.

=COUNTIF(Y2:Y505,"<"&TIME(0,2,0))

However, when I tried to code that formula using VBA it returned a different number instead. Wonder if someone could point out what I did wrong.

Code:
finalRow = ThisWorkbook.Worksheets("Paste").Cells(Sheets("Paste").Rows.Count, "A").End(xlUp).Row
ThisWorkbook.Worksheets("Summary").Range("B7").Formula = WorksheetFunction.CountIf(ThisWorkbook.Worksheets("Paste").Range("Y2:Y" & finalRow), "<" & Time(0, 2, 0))

I'm trying to count the number of rows that have time less than 2 mins.

Thank you!
 

Some videos you may like

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
6,781
Office Version
  1. 365
Platform
  1. Windows
Instead of:
Code:
& Time(0, 2, 0)

Try:
Code:
& TimeValue("00:02:00")
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,109,445
Messages
5,528,800
Members
409,835
Latest member
Mafu1267

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top