excel vba - else if statement defaulting to the last condition vba -


i'm writing macro read column of dates, check month of each item, record number in variable, , put final number in cell. program looking through column of 2999 items. column isn't full. number selected because number of items high.

the each loop checks month each cell , increases month's variable 1. @ end, december variable around 2500. there 500 filled rows. sum of months comes 2999 (the number of rows being searched). i'm not sure why it's doing this. tried adding "else" condition. it's not reaching far. a15 never filled "batman". have missing simple. help?

dim rng3 range dim jancount integer dim febcount integer dim marcount integer dim aprcount integer dim maycount integer dim juncount integer dim julcount integer dim augcount integer dim sepcount integer dim octcount integer dim novcount integer dim deccount integer dim datevalue date dim monthint integer  set rng3 = sheets("sheet2").range("k2:k3000")  each cell in rng3 datevalue = cell.value monthint = month(datevalue)  if monthint = 1     jancount = jancount + 1  elseif monthint = 2     febcount = febcount + 1  elseif monthint = 3     marcount = marcount + 1  elseif monthint = 4     aprcount = aprcount + 1  elseif monthint = 5     maycount = maycount + 1  elseif monthint = 6     juncount = juncount + 1  elseif monthint = 7     julcount = julcount + 1  elseif monthint = 8     augcount = augcount + 1  elseif monthint = 9     sepcount = sepcount + 1  elseif monthint = 10     octcount = octcount + 1  elseif monthint = 11     novcount = novcount + 1  elseif monthint = 12     deccount = deccount + 1  else     sheets("sheet1").range("a15") = "batman"  end if  next cell  sheets("sheet1").range("a10") = "bugs in jan" sheets("sheet1").range("b10") = "bugs in feb" sheets("sheet1").range("c10") = "bugs in mar" sheets("sheet1").range("d10") = "bugs in apr" sheets("sheet1").range("e10") = "bugs in may" sheets("sheet1").range("f10") = "bugs in jun" sheets("sheet1").range("g10") = "bugs in jul" sheets("sheet1").range("h10") = "bugs in aug" sheets("sheet1").range("j10") = "bugs in oct" sheets("sheet1").range("k10") = "bugs in nov" sheets("sheet1").range("l10") = "bugs in dec"  sheets("sheet1").range("a11") = jancount sheets("sheet1").range("b11") = febcount sheets("sheet1").range("c11") = marcount sheets("sheet1").range("d11") = aprcount sheets("sheet1").range("e11") = maycount sheets("sheet1").range("f11") = juncount sheets("sheet1").range("g11") = julcount sheets("sheet1").range("h11") = augcount sheets("sheet1").range("i11") = sepcount sheets("sheet1").range("j11") = octcount sheets("sheet1").range("k11") = novcount sheets("sheet1").range("l11") = deccount 

replace line

set rng3 = sheets("sheet2").range("k2:k3000") 

with

set rng3 = sheets("sheet2").range("k2:k" & sheets(2).cells(rows.count, 11).end(xlup).row) 

basically s. wirth said, because of blank cells. in above code, instead of making loop till 3000, making take till whatever data there.

hope helps.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -