アプリ版:「スタンプのみでお礼する」機能のリリースについて

タイトル  発売日
タイトルA 1月1日
タイトルB 1月2日
タイトルC 1月2日
タイトルD 2月1日
タイトルE 2月10日
タイトルF 3月3日
タイトルG 3月20日
タイトルH 3月21日
タイトルI  3月21日

タイトルZ 12月31日

というデータがあるとします。
これを一月単位(1月=3件、2月=2件、3月=4件、…12月)で集計したいのです。
どのようにVBAで記述すればいいのでしょか。

for文で、

Sub test()
For 1月 To 12月
if(1月発売日 == ゲーム発売日) Then
     1月カウント合計 = 1月カウント合計 + 1
   End if
Next
End Sub

で書けばいいかなと思っているのですが、
(1)For文の1月から12月の各月カウント記述方法が不明
(2)if文で、1月1日~1月31日 が 1月発売日の条件と一致させて、「 1月カウント合計 = 1月カウント合計 + 1」
カウントさえる記述方法が不明。


どなたかご教授お願いします。

A 回答 (1件)

ただ1月と言っても、今年の1月と去年の1月を一緒に集計しちゃいたいんですか。


みたいな突っ込みはまぁ置いておいて。


sub macro1()
 dim y as integer
 dim m as integer
 dim res(12) as long

 y = 2014
 worksheets("Sheet1").select

 for m = 1 to 12
  res(m) = application.countif(range("B:B"), ">=" & dateserial(y,m,1)) - application.countif(range("B:B"), ">=" & dateserial(y,m+1,1))
  cells(m, "C") = format(dateserial(y,m,1), "yyyy年m月")
  cells(m, "D") = res(m)
 next m
end sub





#それともこーいうのがいいのなら、こんなでも。

sub macro2()
 dim y as integer
 dim r as long
 dim res(12) as long
 dim h as range

 y = 2014
 worksheets("Sheet1").select

 for r = 2 to range("B65536").end(xlup).row
  if isdate(cells(r, "B")) then
   res(month(cells(r, "B"))) = res(month(cells(r, "B"))) + 1
  end if
 next r

 for r = 1 to 12
  cells(r, "E") = res(r)
 next r
end sub

こーいうのだと全データを一個一個舐めまわしてくので、当然遅いです。
    • good
    • 0
この回答へのお礼

ありがとうございます。
何とかできました。

お礼日時:2014/03/05 22:42

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!