下記内容で足りない情報、不明な点あればおしえてください。
プログラムはじめて3か月目です。
前提・実現したいこと
####プログラムの目的
Excelのvbaを使って、idを活用した工程管理をするシステムを作っています。
####前提
idが入力されると
lookat xlwhole でidをexcel内で検索、
もしみつからなければ userform1 で新規のid登録とデータを入力します。
もしみつかればuserform2にそのデータが各入力エリアに入力された状態でuserformがでてきます。
userform2で入力されたものが最新情報としてexcel内のデータに更新されます。
####実現したいこと
入力フォームにすでにある情報は入力されたままで表示したい。
更新された情報として際で抽出してきた先にデータを登録したい。
発生している問題・エラーメッセージ
ecel内にあるデータをtmpdataに'$'でsplitしたものを代入して、
tmpdataをuserform2の対応する各入力フォームに文字列をいれる過程と、
各入力フォームに入力されたデータを再び対応するexcel内にあるデータに入力していく過程で"オブジェクトが必要です"のエラーがおきます。
実行時エラー'427': オブジェクトが必要です。
該当のソースコード
module1
ExcelVBA
1 2tmpData = Split(UserForm2.updateData(id, bnum, bname, cus, dlv, inspection, status, pinc, order1, srsts1, srorder1, inorder1, order2, srsts2, srorder2, inorder2, order3, srsts3, srorder3, inorder3, last), "$") 3
###モジュールと入力フォームのソースコード
Module1 の一部
ExcelVBA
1 2'========== 3'工程更新 4'========== 5 6Sub update(id As String) 7 8 Dim findData As Object 9 Dim bnum As String 10 Dim bname As String 11 Dim cus As String 12 Dim dlv As String 13 Dim status As String 14 Dim inspection As String 15 Dim pinc As String 16 Dim order1 As String 17 Dim srsts1 As String 18 Dim srorder1 As String 19 Dim inorder1 As String 20 Dim order2 As String 21 Dim srsts2 As String 22 Dim srorder2 As String 23 Dim inorder2 As String 24 Dim order3 As String 25 Dim srsts3 As String 26 Dim srorder3 As String 27 Dim inorder3 As String 28 Dim last As String 29 Dim tmpData As Variant 30 31 32 33 With ThisWorkbook.Worksheets(SHT_List) 34 35 Set findData = Nothing 36 Set findData = .Columns(???X?g.IDl_).Find(id, LookAt:=xlWhole) 37 38 bnum = .Cells(findData.row, ???X?g.bnuml_).Value 39 bname = .Cells(findData.row, ???X?g.bnamel_).Value 40 cus = .Cells(findData.row, ???X?g.cusl_).Value 41 dlv = .Cells(findData.row, ???X?g.dlvl_).Value 42 inspection = .Cells(findData.row, ???X?g.insl_).Value 43 status = .Cells(findData.row, ???X?g.stsl_).Value 44 pinc = .Cells(findData.row, ???X?g.pincl_).Value 45 order1 = .Cells(findData.row, ???X?g.ord1l_).Value 46 srsts1 = .Cells(findData.row, ???X?g.srsts1l_).Value 47 srorder1 = .Cells(findData.row, ???X?g.srorder1l_).Value 48 inorder1 = .Cells(findData.row, ???X?g.inorder1l_).Value 49 order2 = .Cells(findData.row, ???X?g.ord2l_).Value 50 srsts2 = .Cells(findData.row, ???X?g.srsts2l_).Value 51 srorder2 = .Cells(findData.row, ???X?g.srorder2l_).Value 52 inorder2 = .Cells(findData.row, ???X?g.inorder2l_).Value 53 order3 = .Cells(findData.row, ???X?g.ord3l_).Value 54 srsts3 = .Cells(findData.row, ???X?g.srsts3l_).Value 55 srorder3 = .Cells(findData.row, ???X?g.srorder3l_).Value 56 inorder3 = .Cells(findData.row, ???X?g.inorder3l_).Value 57 last = .Cells(findData.row, ???X?g.lastl_).Value 58 59 60 tmpData = Split(UserForm2.updateData(id, bnum, bname, cus, dlv, inspection, status, pinc, order1, srsts1, srorder1, inorder1, order2, srsts2, srorder2, inorder2, order3, srsts3, srorder3, inorder3, last), "$") 61 62 63 .Cells(findData.row, ???X?g.bnuml_).Value = tmpData(0) 64 .Cells(findData.row, ???X?g.bnamel_).Value = tmpData(1) 65 .Cells(findData.row, ???X?g.cusl_).Value = tmpData(2) 66 .Cells(findData.row, ???X?g.dlvl_).Value = tmpData(3) 67 .Cells(findData.row, ???X?g.insl_).Value = tmpData(4) 68 .Cells(findData.row, ???X?g.stsl_).Value = tmpData(5) 69 .Cells(findData.row, ???X?g.pincl_).Value = tmpData(6) 70 .Cells(findData.row, ???X?g.ord1l_).Value = tmpData(7) 71 .Cells(findData.row, ???X?g.srsts1l_).Value = tmpData(8) 72 .Cells(findData.row, ???X?g.srorder1l_).Value = tmpData(9) 73 .Cells(findData.row, ???X?g.inorder1l_).Value = tmpData(10) 74 .Cells(findData.row, ???X?g.ord2l_).Value = tmpData(11) 75 .Cells(findData.row, ???X?g.srsts2l_).Value = tmpData(12) 76 .Cells(findData.row, ???X?g.srorder2l_).Value = tmpData(13) 77 .Cells(findData.row, ???X?g.inorder2l_).Value = tmpData(14) 78 .Cells(findData.row, ???X?g.ord3l_).Value = tmpData(15) 79 .Cells(findData.row, ???X?g.srsts3l_).Value = tmpData(16) 80 .Cells(findData.row, ???X?g.srorder3l_).Value = tmpData(17) 81 .Cells(findData.row, ???X?g.inorder3l_).Value = tmpData(18) 82 .Cells(findData.row, ???X?g.lastl_).Value = tmpData(19) 83 84 85 End With 86 87End Sub 88 89 90
userform2のデータ受け渡し部分
ExcelVBA
1Public Function updateData(id As String, bnum As String, bname As String, cus As String, dlv As String, inspection As String, status As String, pinc As String, order1 As String, srsts1 As String, srorder1 As String, inorder1 As String, order2 As String, srsts2 As String, srorder2 As String, inorder2 As String, order3 As String, srsts3 As String, srorder3 As String, inorder3 As String, last As String) 2 Dim result As String 3 4 5 idlabel.Caption = id 6 bnumbox.Value = bnum 7 bnamebox.Value = bname 8 cusbox.Value = cus 9 dlvbox.Value = dlv 10 stsbox.Value = status 11 pincbox.Value = pinc 12 insbox.Value = inspection 13 orderbox1.Value = order1 14 srstsbox1.Value = srsts1 15 srorderbox1.Value = srorder1 16 inorderbox1.Value = inoreder1 17 orderbox2.Value = order2 18 srstsbox2.Value = srsts2 19 srorderbox2.Value = srorder2 20 inorderbox2.Value = inorder2 21 orderbox3.Value = order3 22 srstsbox3.Value = srsts3 23 srorderbox3.Value = srorder3 24 inorderbox3.Value = inorder3 25 lastbox.Value = last 26 27 28 29 30 Me.Show 31 32 result = bnumbox.Value & "$" & bnamebox.Value & "$" & cusbox.Value & "$" & dlvbox.Value & "$" & stsbox.Value & "$" & pincbox.Value & "$" & insbox.Value & "$" & orderbox1.Value & "$" & srstsbox1.Value & "$" & srorderbox1.Value & "$" & inorderbox1.Value & "$" & orderbox2.Value & "$" & srstsbox2.Value & "$" & srorderbox2.Value & "$" & inorderbox2.Value & "$" & orderbox3.Value & "$" & srstsbox3.Value & "$" & srorderbox3.Value & "$" & inorderbox3.Value & "$" & lastbox.Value 33 updateData = result 34 35 36 37 38End Function 39 40
試したこと
以前に同じような症状があった時、単純なスペルミスが原因だったので、コードを印刷して全てスペルチェックしました。
また、コピペで入力することで入力ミスを減らすようにしました。
result の中身や変数宣言時の順番などを入れ替えたりしました。
このコードネットに落ちてたものを流用しました。
もとのコードがちゃんと動くか確認し動くことを確認しました。
そのコードと自分のコードを並べて相違点を洗い出しできるだけ同じおうな処理になるように調整しました。
補足情報(FW/ツールのバージョンなど)
excel2010を使っています。
####よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/04/27 04:08