advanced help
per page, with , order by , clip by
Results of 1 - 1 of about 37700 for IF (0.007 sec.)
[[20150523111041]]
#score: 1591
@digest: 9a8e880b83522c7a58cf87bb4a0166bd
@id: 68049
@mdate: 2015-05-23T20:06:41Z
@size: 7200
@type: text/plain
#keywords: couni (33832), 台紙 (23445), 刷次 (19277), 名fo (17501), checkbox11 (17497), checkbox (14727), checkbox23 (14426), checkbox20 (13814), 合a6 (10933), 紙") (10299), controls (10211), checkbox3 (9738), にch (6537), ルお (6089), caption (6081), printout (4506), checkbox2 (3797), control (3762), selectedsheets (3761), typename (3756), copies (3229), unload (2780), クボ (2753), のca (2484), マナ (2380), clearcontents (2146), activewindow (2051), hide (1915), 印刷 (1892), 土) (1801), 2015 (1750), a6 (1404)
『印刷エラー』(エクセルおじさん)
以下のコードで印刷を行っていますが、チェックボックスを追加すると エラーとなります。 エラー回避の方法を教示願います。 Private Sub CommandButton2_Click() Dim i As Long, couni As Long With Worksheets("台紙") '印刷するシート名 For i = 0 To Me.Controls.Count - 1 If TypeName(Me.Controls(i)) = "CheckBox" Then If Me.Controls("CheckBox" & i + 1).Value = True Then If (couni Mod 2) <> 0 Then .Range("a6").Value = Me.Controls("CheckBox" & i + 1).Caption Else .Range("a6").Value = Me.Controls("CheckBox" & i + 1).Caption Me.Hide ActiveWindow.SelectedSheets.PrintOut Copies:=1 .Range("a6").ClearContents End If End If End If Next i If (couni Mod 2) <> 0 Then Me.Hide ActiveWindow.SelectedSheets.PrintOut Copies:=1 .Range("a6").ClearContents End If End With Unload Me End Sub 尚、エラーは、 If Me.Controls("CheckBox" & i + 1).Value = True Then で発生します。 今後、チェックボックスを10個程追加の予定です。 < 使用 Excel:Excel2010、使用 OS:Windows7 > ---- エラーメッセージを書いてもらえますか? (γ) 2015/05/23(土) 11:35 ---- γさんへ 早々の対応有難うございます。 エラーは、「指定されたオブジェクトは見つかりません」です。 宜しくお願いします。 (エクセルおじさん) 2015/05/23(土) 11:45 ---- ここを参考にするとよいです http://officetanaka.net/excel/vba/tips/tips44.htm (マナ) 2015/05/23(土) 11:48 ---- マナさんへ 参考にさせて頂いてますが、 私の技量では難しい状態です。 現在、印刷終了後にエラー表示です。 (エクセルおじさん) 2015/05/23(土) 12:49 ---- 現在のコードでいらなそうな部分を除いて これでは、どうなりますか? Private Sub CommandButton2_Click() Dim c As Control With Worksheets("台紙") '印刷するシート名 For Each c In Controls If TypeName(c) = "CheckBox" Then If c.Value = True Then .Range("a6").Value = c.Caption .PrintOut End If End If Next .Range("a6").ClearContents End With Unload Me End Sub (マナ) 2015/05/23(土) 13:54 ---- マナさんへ 思う通りに出来ました。 有難うございます。 済みませんが、後、1つ同様な内容をお伺いさせて下さい。 以下のコードで異常はなかったのですが、チェックボックスを 追加したら同様なエラーとなります。 対象せるが2つ(a6,a8)になった場合はどうなるでしょか。 Private Sub CommandButton1_Click() Dim i As Long, couni As Long With Worksheets("台紙") '印刷するシート名 For i = 0 To Me.Controls.Count - 1 If TypeName(Me.Controls(i)) = "CheckBox" Then If Me.Controls("CheckBox" & i + 1).Value = True Then 'ここでエラー couni = couni + 1 If (couni Mod 2) <> 0 Then .Range("a6").Value = Me.Controls("CheckBox" & i + 1).Caption Else .Range("a8").Value = Me.Controls("CheckBox" & i + 1).Caption Me.Hide ActiveWindow.SelectedSheets.PrintOut Copies:=1 .Range("a6,a8").ClearContents End If End If End If Next i If (couni Mod 2) <> 0 Then Me.Hide ActiveWindow.SelectedSheets.PrintOut Copies:=1 .Range("a6,a8").ClearContents End If End With Unload Me End Sub (エクセルおじさん) 2015/05/23(土) 14:22 ---- a6とa8をどういうルールで区別するか不明ですが? Private Sub CommandButton1_Click() Dim c As Control Dim v Dim n As String v = Array("CheckBox11", "CheckBox5", "CheckBox7") '★a6に転記するものを列挙 With Worksheets("台紙") '印刷するシート名 For Each c In Controls If TypeName(c) = "CheckBox" Then If c.Value = True Then n = c.Caption If IsNumeric(Application.Match(n, v, 0)) Then .Range("a6").Value = n Else .Range("a8").Value = n End If .PrintOut .Range("a6,a8").ClearContents End If End If Next End With Unload Me End Sub (マナ) 2015/05/23(土) 15:41 修正15:57 また修正20:01 ---- .Range("a6").ClearContents の位置を修正しました。 (マナ) 2015/05/23(土) 15:59 ---- 改めて見直すとSelect Caseの意味ありませんでした。 If IsNumeric(Application.Match(n, v, 0)) Then .Range("a6").Value = n Else .Range("a8").Value = n End If (マナ) 2015/05/23(土) 20:03 ---- マナさんへ ご教示誠に有難うございます。 現在、移動中で閲覧させて頂きました。 コードの試行は、明日になるかと思います。 a6とa8の区別の件ですが、 チェックボックスを23個設定しています。その中から 選択したチェックボックスのCaptionをa6とa8に入れて印刷することです。 例1: CheckBox1,CheckBox3,CheckBox6,CheckBox10,を選択した場合 a6に CheckBox1 a8にCheckBox3のCaptionを表示して印刷 次に a6に CheckBox6 a8にCheckBox10のCaptionを表示して印刷する。 例2: CheckBox2,CheckBox3,CheckBox11,CheckBox20,,CheckBox23を選択した場合 a6に CheckBox2 a8にCheckBox3のCaptionを表示して印刷 次に a6に CheckBox11 a8にCheckBox20のCaptionを表示して印刷 次に a6に CheckBox23を表示して印刷する。 以上が目的としている動作です。 (エクセルおじさん) 2015/05/23(土) 22:44 ---- ならば、こんな感じですが、 今のコードの Controls("CheckBox" & i + 1) を Controls(i) にするだけでもよかったです。 Private Sub CommandButton1_Click() Dim c As Control Dim flg As Boolean Dim n As String With Worksheets("台紙") '印刷するシート名 For Each c In Controls If TypeName(c) = "CheckBox" Then If c.Value = True Then n = c.Caption If flg = False Then .Range("a6").Value = n flg = True Else .Range("a8").Value = n .PrintOut .Range("a6,a8").ClearContents flg = False End If End If End If Next If flg = True Then .PrintOut .Range("a6").ClearContents End If End With Unload Me End Sub (マナ) 2015/05/23(土) 23:41 ---- マナさんへ 只今、試行してみました。 目的としていた動作となりました。 誠に有難うございます。 今後、コードを読み解き 技量向上に努めたいと思います。 (エクセルおじさん) 2015/05/24(日) 05:06 ...
https://www.excel.studio-kazu.jp/wiki/kazuwiki/201505/20150523111041.txt - [detail] - similar
PREV NEXT
Powered by Hyper Estraier 1.4.13, with 97065 documents and 608341 words.

訪問者:カウンタValid HTML 4.01 Transitional