vba - Excel VB Macro compare values in entire column -
i'm new macros , i'm trying learn how write simple expressions. i'd compare values in single column see if match current day of month.
for example: column h contains number corresponds random day of month. i'd know how write expression in macro if today == value in column h (in other words, if today 19th , value in column h 19) change cell text color red (or other action).
so far know how select range of cells using: range("b2, c7, i8") don't know how select entire column. can tell me how write such expression?
*note: i'm not talking comparing columns across sheets. need compare values in 1 column current date. thanks!
to act on entire column, either of these lines work:
range("a:a") columns("a")
as checking if column contains specific criteria, recommend using worksheet formula countif:
msgbox worksheetfunction.countif(columns("a"), day(now)) > 0
to find cells within column contain criteria, can use range.find method:
dim rngfound range dim strfirst string dim ldaynum long ldaynum = day(now) columns("a").interior.color = xlnone set rngfound = columns("a").find(ldaynum, cells(rows.count, "a"), xlvalues, xlwhole) if not rngfound nothing strfirst = rngfound.address rngfound.interior.color = rgb(255, 0, 0) set rngfound = columns("a").find(ldaynum, rngfound, xlvalues, xlwhole) loop while rngfound.address <> strfirst end if
lastly, more accomplished conditional formatting.
Comments
Post a Comment