excel vba - Today function equivalent in VBA in combination with countifs -
i having problem using countifs formula in excel / vba. have got formula working perfect in excel ideally want use in vba form. here formula in excel works treat:
=countifs(sheet1!a:a,"place",sheet1!k:k,"<"&today()) will count names places in past
=countifs(sheet1!a:a,"place",sheet1!k:k,">"&today()) will count names places current
i have 5 different places in column , hundreds of different dates in column k. above formulas work in excel , return correct values. have spent hours trying work in vba userform keep getting various errors. first part not problem &today function falls apart. can see &today function not available in vba , &date seems recommendation. have tried still no where. i'm missing trick (or several) here , working in vba rather using current formulas in excel. returned results displayed in textboxes on form.
all ideas , feedback welcome!
second edit
================================
thanks quick replies! here actual code playing in vba
'count events area' dim listlondon long listlondon = .countif(range("a1:a1998"), "london"), ("sheet1!k1:k1998"), "<" & date) end me.textbox1 = listlondon i know second part of count if wrong regards date - that's how i've left now. hoping use current layout , working date / today code @ end. please show me i've done wrong here!
====
oops - can see mistake - initial problem remains around date issue. should of used countifs using multiple criteria.
you have read values of cells vba code. recommend use excel.range object that. can interpret range edit line of excel, like
dim foo excel.range
set foo = yourworksheet.range("a1:b3")
read date type data vba date type variable iterating through cells.
examine relation between read data , current date. current date can read using datetime.now function.
increment variable based on decision
Comments
Post a Comment