お久しぶりです。pipiでございます。
金額を合計する関数MyCalc()を標準モジュールに移動し呼び出そうとしておりますが、
**Function GetGoukeiKingaku関数で『型が一致しません』**というエラーになり四苦八苦しております。。。
金額を合計する関数MyCalc()は、元々、Private sub btnAdd_Click()プロージャーと同じ
プロージャー内にあったのですが、他のフォーム上からも呼び出せるようにするため移動しました。。
移動したとたん、なぜか**Function GetGoukeiKingaku関数で『型が一致しません』**というエラーです。
元々のコード↓
Private Sub btnAdd_Click() ' 明細行をリストボックス(lstMeisai)に追加する。 With lstMeisai .AddItem 0 .List(.ListCount - 1, 1) = cboGoodsID.Text .List(.ListCount - 1, 2) = txtGoodsName.Text .List(.ListCount - 1, 3) = Format(txtGoodsPrice, "##,#0") .List(.ListCount - 1, 4) = Format(txtQuantity, "##,#0") .List(.ListCount - 1, 5) = txtGoodsUnit.Text .List(.ListCount - 1, 6) = txtAmount.Text .List(.ListCount - 1, 7) = txtTax.Text .List(.ListCount - 1, 8) = txtSumWithTax.Text End With ' リストボックス内の税込金額を合計する関数GetGoukeikingakuの呼び出し。 lblGoukeiKingaku.Caption = Format(GetGoukeiKingaku(8, lstMeisai), "#,##0") ClerMeisaiRecord Me cboGoodsID.SetFocus btnAdd.Enabled = False End Sub Private Sub MyCalc() On Error GoTo eh Dim Kingaku As Long Kingaku = txtGoodsPrice.Text * txtQuantity.Text On Error GoTo 0 txtAmount.Text = Format(Kingaku, "##,#0") txtTax.Text = Format(Kingaku * 0.08, "##,#0") txtSumWithTax.Text = Format(Kingaku * 1.08, "##,#0") Exit Sub eh: End Sub Public Function GetGoukeiKingaku(ByVal ColumNo As Integer, ByVal LB As MSForms.ListBox) As Long ' 第二引数のリストボックスのにおける第一引数の列の合計を算出する関数 Dim c As Integer c = LB.ListCount - 1 If c = -1 Then GetGoukeiKingaku = 0 Exit Function End If Dim Ans As Long Dim i As Integer Ans = 0 For i = 0 To c Ans = Ans + LB.List(i, ColumNo) Next GetGoukeiKingaku = Ans
金額を合計する関数MyCalc()を標準モジュールに移動
`標準モジュールに記載 Public Sub MyCalc(ByRef TarGetForm As MSForms.UserForm) With TarGetForm On Error GoTo eh Dim Kingaku As Long Kingaku = txtGoodsPrice.Text * txtQuantity.Text On Error GoTo 0 .txtAmount.Text = Format(Kingaku, "##,#0") .txtTax.Text = Format(Kingaku * 0.08, "##,#0") .txtSumWithTax.Text = Format(Kingaku * 1.08, "##,#0") Exit Sub eh: .txtAmount.Text = "" .txtTax.Text = "" .txtSumWithTax.Text = "" End With End Sub
Public Function GetGoukeiKingaku(ByVal ColumNo As Integer, ByVal LB As MSForms.ListBox) As Long ' 第二引数のリストボックスのにおける第一引数の列の合計を算出する関数 Dim c As Integer c = LB.ListCount - 1 If c = -1 Then GetGoukeiKingaku = 0 Exit Function End If Dim Ans As Long Dim i As Integer Ans = 0 For i = 0 To c Ans = Ans + LB.List(i, ColumNo) `MyCalc()を標準モジュールに記載するとここでエラーとなる。 Next GetGoukeiKingaku = Ans
説明が悪くて申し訳ありませんが、どなたかご教授いただけららと思います。



回答4件
あなたの回答
tips
プレビュー