| 
    
     |  | はじめまして。今、VBAを勉強しているものです。ウィンドウを表示させ、そこにIDを入力するとシートのA列にIDを表示させ、B列には名前、C列には出勤時間を表示させ、もう一度IDを入力すると退勤時間がD列に表示されるものを作成しています。 下記に示してあるのですが、名前の表示の際の列の指定の所でエラーが起きてしまいます。どのように変更したらようのか教えて下さい。よろしくおねがいします。
 
 
 Private Sub CommandButton1_Click()
 Dim Rng As Range
 Dim Col As Integer
 Dim id As String
 Dim str As String
 Dim FoundCell As Range
 Dim joh As Range
 
 
 '名前を表示
 id = TextBox1.Value
 Set FoundCell = Range("T:T").Find(What:=TextBox1)
 If FoundCell Is Nothing Then
 MsgBox "番号がありません"
 Else
 MsgBox FoundCell.Offset(0, 1)
 If Not FoundCell Is Nothing Then
 Range("B") = FoundCell.Next      ←ここの部分
 End If
 End If
 
 id = TextBox1.Value
 With Worksheets("Sheet1")
 '重複のチェック
 If Application.WorksheetFunction.CountIf(.Range("A:A"), id) = o Then
 '出勤処理
 Col = 2 'B列
 Set Rng = .Range("A" & Rows.Count).End(xlUp).Offset(1) 'A列最終行の取得
 Rng.Value = id '番号出力
 Else
 '退勤処理
 Set Rng = .Range("A:A").Find(id)
 Col = 3 'C列
 End If
 End With
 '時刻出力
 With Rng.Offset(, Col)
 .Value = Now() '時刻出力
 .NumberFormat = "yy/mm/dd hh:mm" 'セルの書式設定
 End With
 
 TextBox1.Value = ""
 TextBox1.SetFocus
 
 str = "完了"
 MsgBox (str)
 
 
 End Sub
 
 
 |  |