今excelのVBAを使って属している施設の利用案内システムを作っています。
excelのF7のセルに施設を利用する時間(例:午前なら前、午後なら後 という感じ)を入力するとその時間と対応したセルに〇がつくという機能を実装中です。
午前、午後、夜間 まではプログラムをつくることができました。
しかし、午前中から午後まで利用する場合のプログラムがなかなかうまくいかずエラーになります。
午前中から午後まで利用する場合は3つのセルに同時に〇が出るようにしなくてはなりません。
発生している問題・エラーメッセージ
Valueメソッドは失敗しました Rangeオブジェクト
該当のソースコード
VBA
1 If WS.Cells(7, "F").Value = G Then 'F7に前後 2 WS.Range(WS.Cells(7, "I"), WS.Cells(7, "K")).Value = "●" 3 End If 4
試したこと
表記の方法を変えてみました。
・WS.Range("I7:K7").Value="●"
・FormulaR1C1を使う
補足情報(FW/ツールのバージョンなど)
excelは2010のものだとおもいます。
WS.Range("I7").Value="●"
WS.Range("J7").Value="●"
WS.Range("K7").Value="●"
「午前、午後、夜間 まではプログラムをつくることができました。」出来たとこまでのプログラムを載せてもらえませんか?
できているところまでのプログラムです。
Private wf As WorksheetFunction
Option Base 1
Private Sub Worksheet_Change(ByVal Target As Range)
'Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim RX, RY As Integer
Dim WS As Worksheet
RX = Target.Row
RY = Target.Column
Dim N, P, R, O, G As Variant
P = "●"
N = "前"
O = "後"
R = "夜"
G = "前後"
Q = "後夜"
B = "全"
Set wf = Application.WorksheetFunction
Set WS = ThisWorkbook.Worksheets("申込明細2")
'●を出力
If WS.Cells(7, "F").Value = N Then 'F7に前
WS.Cells(7, "I").Value = P
If WS.Cells(7, "K").Value = P Then 'K7に●
WS.Cells(7, "K").ClearContents
End If
If WS.Cells(7, "M").Value = P Then 'M7に●
WS.Cells(7, "M").ClearContents
End If
If WS.Cells(7, "J").Value = P Then 'J7に●
WS.Cells(7, "J").ClearContents
End If
If WS.Cells(7, "L").Value = P Then 'L7に●
WS.Cells(7, "L").ClearContents
End If
If WS.Cells(7, "N").Value = P Then 'N7に●
WS.Cells(7, "N").ClearContents
End If
If WS.Cells(7, "H").Value = P Then 'H7に●
WS.Cells(7, "H").ClearContents
End If
End If
If WS.Cells(7, "F").Value = O Then 'F7に後
WS.Cells(7, "K").Value = P
If WS.Cells(7, "I").Value = P Then 'I7に●
WS.Cells(7, "I").ClearContents
End If
If WS.Cells(7, "M").Value = P Then 'M7に●
WS.Cells(7, "M").ClearContents
End If
If WS.Cells(7, "H").Value = P Then 'H7に●
WS.Cells(7, "H").ClearContents
End If
If WS.Cells(7, "J").Value = P Then 'J7に●
WS.Cells(7, "J").ClearContents
End If
If WS.Cells(7, "L").Value = P Then 'L7に●
WS.Cells(7, "L").ClearContents
End If
If WS.Cells(7, "N").Value = P Then 'N7に●
WS.Cells(7, "N").ClearContents
End If
End If
If WS.Cells(7, "F").Value = R Then 'F7に夜
WS.Cells(7, "M").Value = P
If WS.Cells(7, "I").Value = P Then 'I7に●
WS.Cells(7, "I").ClearContents
End If
If WS.Cells(7, "K").Value = P Then 'K7に●
WS.Cells(7, "K").ClearContents
End If
If WS.Cells(7, "H").Value = P Then 'H7に●
WS.Cells(7, "H").ClearContents
End If
If WS.Cells(7, "J").Value = P Then 'J7に●
WS.Cells(7, "J").ClearContents
End If
If WS.Cells(7, "L").Value = P Then 'L7に●
WS.Cells(7, "L").ClearContents
End If
If WS.Cells(7, "N").Value = P Then 'N7に●
WS.Cells(7, "N").ClearContents
End If
End If
あなたの回答
tips
プレビュー