[ 初めての方へ | 一覧(最新更新順) | 全文検索 | 過去ログ ]
『コンパイルエラー:End Withに対応するWithがありません』(ルビィ)
当方、初めてユーザーフォームを作成しました。
ネットで調べつつ、シンプルで項目数が少ないファイルでは上手く動作したのですが、項目数を増やしたところコンパイルエラーが出てしまいました。
ユーザーフォームに入力するコードとセルの値を取得するコードです。
なぜエラーになるのかわかりません。
With〜End Withにしていると思うのですが・・・
ご教示いただけますでしょうか?
宜しくお願いいたします。
Private ActiveRow As Long
Private blnOk As Boolean
Public Function doModal(ByVal argRow As Long) As Boolean
Dim i As Integer ActiveRow = argRow
With Worksheets("管理表") If .Cells(ActiveRow, 1) = "完了" Then Me.chk完了.Value = True Else Me.chk完了.Value = False End If Me.A日付txt.Text = .Cells(ActiveRow, 2) Me.A対応者txt.Text = .Cells(ActiveRow, 3) Me.A対応時間txt.Text = .Cells(ActiveRow, 4) Me.A種別txt.Text = .Cells(ActiveRow, 5) Me.A氏名漢字txt.Text = .Cells(ActiveRow, 8) Me.A氏名カナtxt.Text = .Cells(ActiveRow, 9) Me.A電話番号txt.Text = .Cells(ActiveRow, 10) Me.A生年月日txt.Text = .Cells(ActiveRow, 11) Me.A性別txt.Text = .Cells(ActiveRow, 12) Me.A年齢txt.Text = .Cells(ActiveRow, 13) Me.A職業txt.Text = .Cells(ActiveRow, 14) Me.A都道府県txt.Text = .Cells(ActiveRow, 15) Me.B営業所txt.Text = .Cells(ActiveRow, 19) Me.D備考txt.Text = .Cells(ActiveRow, 28) Me.B電話担当者txt.Text = .Cells(ActiveRow, 29) Me.B電話電話番号txt.Text = .Cells(ActiveRow, 30) Me.C確定日txt.Text = .Cells(ActiveRow, 38) Me.C曜日txt.Text = .Cells(ActiveRow, 39) Me.C時間txt.Text = .Cells(ActiveRow, 40) Me.C充足状況txt.Text = .Cells(ActiveRow, 47) Me.C備考txt.Text = .Cells(ActiveRow, 50)
For i = 0 To Me.D状況cmb.ListCount - 1 If Me.D状況cmb.List(i) = .Cells(ActiveRow, 26) Then Me.D状況cmb.ListIndex = i Exit For End If Next For i = 0 To Me.Dステータスcmb.ListCount - 1 If Me.Dステータスcmb.List(i) = .Cells(ActiveRow, 27) Then Me.Dステータスcmb.ListIndex = i Exit For End If Next For i = 0 To Me.E報告cmb.ListCount - 1 If Me.E報告cmb.List(i) = .Cells(ActiveRow, 36) Then Me.E報告cmb.ListIndex = i Exit For End If Next For i = 0 To Me.ECB有cmb.ListCount - 1 If Me.ECB有cmb.List(i) = .Cells(ActiveRow, 37) Then Me.ECB有cmb.ListIndex = i Exit For End If Next For i = 0 To Me.C確認コール1cmb.ListCount - 1 If Me.C確認コール1cmb.List(i) = .Cells(ActiveRow, 48) Then Me.C確認コール1cmb.ListIndex = i Exit For End If Next For i = 0 To Me.C確認コール2cmb.ListCount - 1 If Me.C確認コール2cmb.List(i) = .Cells(ActiveRow, 49) Then Me.C確認コール2cmb.ListIndex = i Exit For End If End With
blnOk = False Me.Show doModal = blnOk End Function
With Worksheets("管理表") If Me.chk完了.Value = True Then .Cells(ActiveRow, 1) = "完了" Else .Cells(ActiveRow, 1) = "" End If .Cells(ActiveRow, 2) = Me.A日付txt.Text .Cells(ActiveRow, 3) = Me.A対応者txt.Text .Cells(ActiveRow, 4) = Me.A時間txt.Text .Cells(ActiveRow, 5) = Me.A種別txt.Text .Cells(ActiveRow, 8) = Me.A氏名漢字txt.Text .Cells(ActiveRow, 9) = Me.A氏名カナtxt.Text .Cells(ActiveRow, 10) = Me.A電話番号txt.Text .Cells(ActiveRow, 11) = Me.A生年月日txt.Text .Cells(ActiveRow, 12) = Me.A性別txt.Text .Cells(ActiveRow, 13) = Me.A年齢txt.Text .Cells(ActiveRow, 14) = Me.A職業txt.Text .Cells(ActiveRow, 15) = Me.A都道府県txt.Text .Cells(ActiveRow, 19) = Me.B営業所txt.Text .Cells(ActiveRow, 26) = Me.D状況cmb.List .Cells(ActiveRow, 27) = Me.Dステータスcmb.List .Cells(ActiveRow, 28) = Me.D備考txt.Text .Cells(ActiveRow, 29) = Me.B電話担当者txt.Text .Cells(ActiveRow, 30) = Me.B電話電話番号txt.Text .Cells(ActiveRow, 36) = Me.E報告cmb.List .Cells(ActiveRow, 37) = Me.ECB有cmb.List .Cells(ActiveRow, 48) = Me.C確認コール1cmb.List .Cells(ActiveRow, 49) = Me.C確認コール2cmb.List .Cells(ActiveRow, 50) = Me.C備考txt.Text Select Case True Case Me.optOK.Value .Cells(ActiveRow, 8) = "OK" Case Me.optNG.Value .Cells(ActiveRow, 8) = "NG" Case Me.opt未.Value .Cells(ActiveRow, 8) = "" Case Else .Cells(ActiveRow, 8) = "" End Select End With blnOk = True Me.Hide End Sub
< 使用 Excel:Excel2010、使用 OS:Windows7 >
For i = 0 To Me.C確認コール2cmb.ListCount - 1 If Me.C確認コール2cmb.List(i) = .Cells(ActiveRow, 49) Then Me.C確認コール2cmb.ListIndex = i Exit For End If End With が対応していません。 For .. Next の問題ですけどね。メッセージに惑わされてはいけない。
内容は見ておりません。 (γ) 2016/08/24(水) 20:52
横から失礼します。
メモ帳などでコードを書く場合は、
With書いたら直下にEnd Withを書く。
Ifを書いたら直下にEnd Ifを書く。(End Ifが不要な場合もあるけど)
というように習慣づけたらこのような間違いは起こしにくくなります。 (カリーニン) 2016/08/24(水) 21:08
For i = 0 To Me.C確認コール2cmb.ListCount - 1
If Me.C確認コール2cmb.List(i) = .Cells(ActiveRow, 49) Then Me.C確認コール2cmb.ListIndex = i Exit For End If End With
が対応していないという意味がわかりませんでした。
素人の質問で申し訳ありません。
メッセージに惑わされてはいけない、というのは
With〜End With は正しいが
他のコードが間違えているということでしょうか?
For〜Nextの使い方でしょうか?
何度もお手数をおかけしますが
宜しくお願いします
(ルビィ) 2016/08/24(水) 21:25
(γ) 2016/08/24(水) 21:33
ありがとうございます。
うまく動きました!
ご面倒をおかけしました。
(ルビィ) 2016/08/24(水) 21:37
[ 一覧(最新更新順) ]
YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki.
Modified by kazu.