構文------------------------------------- Dim myRoom As Integer, intRow As Integer, Ob As Integer Worksheets("データ一覧").Activate myRoom = ComboBox3 '部屋番号検索 Worksheets("データ一覧").Columns("A:A").Find(What:=myRoom, LookIn:=xlFormulas, LookAt:=xlWhole).Activate intRow = ActiveCell.Row
For Ob = 1 To 3 If Controls("OptionButton" & Ob).Value = True Then '生年月日年号判別 Cells(intRow, 99).Value = Ob End If Next Ob
For Ob = 4 To 5 If Controls("OptionButton" & Ob).Value = True Then '性別判別 Cells(intRow, 100).Value = Ob - 3 End If Next Ob
For Ob = 6 To 10 If Controls("OptionButton" & Ob).Value = True Then '介護度判別 Cells(intRow, 101).Value = Ob - 5 End If Next Ob
For Ob = 11 To 14 If Controls("OptionButton" & Ob).Value = True Then '医療保険判別 Cells(intRow, 102).Value = Ob - 10 End If Next Ob
For Ob = 15 To 18 If Controls("OptionButton" & Ob).Value = True Then '食事判別 Cells(intRow, 103).Value = Ob - 14 End If Next Ob
For Ob = 19 To 22 If Controls("OptionButton" & Ob).Value = True Then '移動判別 Cells(intRow, 104).Value = Ob - 18 End If Next Ob
For Ob = 23 To 25 If Controls("OptionButton" & Ob).Value = True Then '排泄判別 Cells(intRow, 105).Value = Ob - 22 End If Next Ob
For Ob = 26 To 28 If Controls("OptionButton" & Ob).Value = True Then '更衣判別 Cells(intRow, 106).Value = Ob - 25 End If Next Ob
For Ob = 29 To 30 If Controls("OptionButton" & Ob).Value = True Then '麻痺判別 Cells(intRow, 107).Value = Ob - 28 End If Next Ob
For Ob = 31 To 32 If Controls("OptionButton" & Ob).Value = True Then '義歯判別 Cells(intRow, 108).Value = Ob - 30 End If Next Ob
For Ob = 33 To 35 If Controls("OptionButton" & Ob).Value = True Then '視力判別 Cells(intRow, 109).Value = Ob - 32 End If Next Ob
For Ob = 36 To 37 If Controls("OptionButton" & Ob).Value = True Then '聴力判別 Cells(intRow, 110).Value = Ob - 35 End If Next Ob
For Ob = 38 To 39 If Controls("OptionButton" & Ob).Value = True Then '妄想判別 Cells(intRow, 111).Value = Ob - 37 End If Next Ob
For Ob = 40 To 41 If Controls("OptionButton" & Ob).Value = True Then '健忘判別 Cells(intRow, 112).Value = Ob - 39 End If Next Ob
For Ob = 42 To 43 If Controls("OptionButton" & Ob).Value = True Then '見当識判別 Cells(intRow, 113).Value = Ob - 41 End If Next Ob
For Ob = 44 To 45 If Controls("OptionButton" & Ob).Value = True Then '理解力判別 Cells(intRow, 114).Value = Ob - 43 End If Next Ob
For Ob = 46 To 47 If Controls("OptionButton" & Ob).Value = True Then '入浴判別 Cells(intRow, 115).Value = Ob - 45 End If Next Ob
For Ob = 48 To 49 If Controls("OptionButton" & Ob).Value = True Then '徘徊判別 Cells(intRow, 116).Value = Ob - 47 End If Next Ob
For Ob = 50 To 51 If Controls("OptionButton" & Ob).Value = True Then '睡眠判別 Cells(intRow, 117).Value = Ob - 49 End If Next Ob
For Ob = 52 To 53 If Controls("OptionButton" & Ob).Value = True Then '言語障害判別 Cells(intRow, 118).Value = Ob - 51 End If Next Ob
For Ob = 54 To 55 If Controls("OptionButton" & Ob).Value = True Then '不潔行為判別 Cells(intRow, 119).Value = Ob - 53 End If Next Ob
For Ob = 56 To 57 If Controls("OptionButton" & Ob).Value = True Then '意思疎通判別 Cells(intRow, 120).Value = Ob - 55 End If Next Ob
For Ob = 58 To 59 If Controls("OptionButton" & Ob).Value = True Then '認知症判別 Cells(intRow, 121).Value = Ob - 57 End If Next Ob ---------------------------------------- 因みに変数(Ob)を使いまわすのはよくないと調べたら出てきたんですが数が多いので変数を使いまわしています。これもいい方法がないものかと思案中です。
nIndex = 1
For nGroupNo = 1 To UBound(nChoices)
For Ob = 1 To nChoices(i)
If Controls("OptionButton" & nIndex).Value = True Then
Cells(intRow, 98 + nGroupNo).Value = Ob
End If
nIndex = nIndex + 1
Next Ob
Next nGroupNo
これでいかがでしょう。
↓
Sub 処理(ByVal 開始 As Long, ByVal 終了 As Long _
, ByVal 行の位置 As Long, ByVal 列の位置 As Long _
)
Dim Ob As Long
For Ob = 1 To (終了 - 開始 + 1) Step 1
If Controls("OptionButton" & (開始 + Ob - 1)).Value Then
Cells(行の位置, 列の位置).Value = Ob
Exit For 'これだけの処理ならExit Subでも・・・。
End If
Next Ob
End Sub
>>7で「こんな感じかな?」と書いたコードは特に検証していなかったのですが
よくよく見ると構文エラーなとありました(スミマセン)ので微修正してあります。
変数は全て Long 型で受けています。
で、使い方はこう。
↓
Sub 使い方サンプル()
'前略 (変数Obがここで不要なら定義は削除しておいたほうが・・)