…… 店舗名 店舗住所 売上年月日 売上個数 売上金
  本店 埼玉県所沢市…… 2012/7/1 100 210,000
  東京銀座店 東京都銀座一丁目… 2012/6/30 56 117,600
  神奈川店 神奈川県相模原市… 2012/7/10 20 42,000
  品川店 東京都品川区大井… 2012/6/31 21 44,100
  鹿児島一号 鹿児島県…… 2012/7/2 30 63,000
  鹿児島駅店 鹿児島県…… 2012/7/10 60 126,000
  登別店 北海道登別…… 2012/7/11 55 115,500
  …… ……      
  函館店 北海道函館…… 2012/7/1 11 23,100
  札幌一号店 北海道札幌…… 2012/7/5 8 16,800
  札幌駅前店 北海道札幌…… 2012/7/4 4 8,400
  ……        
  大井店 東京都品川区大井… 2012/7/7 90 189,000
           
店舗住所(tenpo)の初めの3文字を抽出 mid(tenpo,1,3) して、北海道であれば、売上金を関数名に入れる。
1) function Prog_1(tenpo as variant , uriage as long) as long
2)    if mid(tenpo,1,3)="北海道" then
3)      prog_1=uriage
4)    else
5)      prog_1=0
6)    end if
7) end
この関数を利用するプログラムは、
1) Dim gokei  as long
2) Dim uriage as long
3) Dim jyusyo as variant
4) Dim j  as integer
5) gokei = 0
6) for j = 2 to 100 step 1
7)    jyusyo = cells( j , 3)
8)    uriage = cells(j j , 4)
9)    gokei = gokei + prog_1(jyusyo , uriage)
10) next j
11) msgbox gokei
12) end
これで、リストの北海道支店の売り上げ集計ができます。同じように、鹿児島県の支店の集計はどうでしょう。関数Prog_1の3行目の"北海道"を"鹿児島"に置き換える必要があります。
しかし、これでは常に県名を直す必要があります。そこで、関数を利用するときに県名を指定するように変更すると、次のようになります。
1) function Prog_1(fuken as variant , tenpo as variant , uriage as long) as integer
2)    if mid(tenpo,1,3) = fuken then
3)      prog_1=uriage
4)    else
5)      prog_1=0
6)    end if
7) end
1) Dim gokei  as long
2) Dim uriage as long
3) Dim fuken as varian
4) Dim jyusyo as variant
5) Dim j  as integer
6) fuken = inputbox( "府県名")
7) gokei = 0
8) for j = 2 to 100 step 1
9)    jyusyo = cells( j , 3)
10)    uriage = cells(j j , 4)
11)    gokei = gokei + prog_1(fuken,jyusyo , uriage)
12) next j
13) msgbox gokei
14) end
朱書きの部分が変更点です。6行目はさまざまな府県を入力する式です。
時間ができたら、この続きを書きます。