我遇到了问题,我尝试了一些转换器和格式更改,但仍然没有得到结果。我有一个用户窗体,可用于在一系列表格中添加或删除清单。 问题是,当仅将来自用户表单的信息添加到“已接收”表中时,不会确认数量单元格。它已填充,但是没有被我已有的表格公式所接受。 我可以到表中并手动输入数量,然后在“数据”选项卡上单击全部刷新,然后正确更新数量。 注意:如果有帮助,我在每个工作表上都设置了数据透视表,以从“已接收”表中获取输入日期,物料和数量,通过用户表格输入的产品的数量为零。* >
Cdbl,Cint,Cdec,Format(),相关Excel表中更改的格式
Private Sub Add_Button_Click()
MsgBox "Are You Sure You Want To Add To Inventory?"
Unload Me
Transaction_Form.Show
Dim the_sheet As Worksheet
Dim table_list_object As ListObject
Dim table_object_row As ListRow
Set the_sheet = Sheets("MATERIALS REC.")
Set table_list_object = the_sheet.ListObjects(1)
Set table_object_row = table_list_object.ListRows.Add
table_object_row.Range(1, 1).Value = CDate(Me.Date_Box)
table_object_row.Range(1, 2).Value = Me.Material_Code_Box
table_object_row.Range(1, 4).Value = Me.Transaction_Qty_Box
table_object_row.Range(1, 5).Value = Me.Mat_Price_Box
table_object_row.Range(1, 6).Value = Me.cboSupplier_List
table_object_row.Range(1, 7).Value = Me.Order_Date_Box
End Sub
Private Sub cboSupplier_List_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
HookListBoxScroll Me, cboSupplier_List
End Sub
Private Sub Date_Box_AfterUpdate()
On Error Resume Next
Me.Date_Box.Value = CDate(Me.Date_Box)
End Sub
Private Sub Mat_Price_Box_AfterUpdate()
On Error Resume Next
Me.Mat_Price_Box.Value = Format(Me.Mat_Price_Box.Value, "$####.##")
End Sub
Private Sub Material_Code_Box_Change()
On Error Resume Next
Me.Material_Code_Box.Value = StrConv(Me.Material_Code_Box.Value, vbUpperCase)
End Sub
Private Sub Next_Button_Click()
MsgBox "The Transaction Form Will Be Closed"
Unload Me
End Sub
Private Sub Order_Date_Box_AfterUpdate()
On Error Resume Next
Me.Order_Date_Box.Value = CDate(Me.Order_Date_Box)
End Sub
Private Sub Overide_Button_Click()
MsgBox "Are You Sure You Want To Overide"
rspn = InputBox("Enter Password")
If rspn <> "ENVenv11" Then
MsgBox "Wrong password"
End If
Unload Me
Transaction_Form.Show
Dim the_sheet As Worksheet
Dim table_list_object As ListObject
Dim table_object_row As ListRow
Set the_sheet = Sheets("MATERIAL USAGE")
Set table_list_object = the_sheet.ListObjects(1)
Set table_object_row = table_list_object.ListRows.Add
table_object_row.Range(1, 1).Value = Me.Date_Box
table_object_row.Range(1, 4).Value = Me.Material_Code_Box
table_object_row.Range(1, 6).Value = Me.Transaction_Qty_Box
table_object_row.Range(1, 3).Value = Me.Process_Box
table_object_row.Range(1, 2).Value = Me.Customer_Box
End Sub
Private Sub Today_Button_Click()
Date_Box.Value = Date
End Sub
Private Sub Transaction_Qty_Box_AfterUpdate()
On Error Resume Next
Me.Transaction_Qty_Box.Value = CDec(Me.Transaction_Qty_Box.Value)
End Sub
Private Sub Use_Button_Click()
MsgBox "Are You Sure You Want To Remove From Inventory"
Unload Me
Transaction_Form.Show
Dim the_sheet As Worksheet
Dim table_list_object As ListObject
Dim table_object_row As ListRow
Set the_sheet = Sheets("MATERIAL USAGE")
Set table_list_object = the_sheet.ListObjects(1)
Set table_object_row = table_list_object.ListRows.Add
table_object_row.Range(1, 1).Value = Me.Date_Box
table_object_row.Range(1, 4).Value = Me.Material_Code_Box
table_object_row.Range(1, 6).Value = Me.Transaction_Qty_Box
table_object_row.Range(1, 3).Value = Me.Process_Box
table_object_row.Range(1, 2).Value = Me.Customer_Box
End Sub
Private Sub UserForm_Click()
End Sub
Private Sub UserForm_Initialize()
'Populate Supplier combo box.
Dim rngSupplier As Range
Dim ws As Worksheet
Set ws = Worksheets("Lookup_Lists")
For Each rngSupplier In ws.Range("Suppliers")
Me.cboSupplier_List.AddItem rngSupplier.Value
Next rngSupplier
End Sub
按下添加按钮时,将在已接收表中填充数量单元。将数据放入表中不会发生任何问题。
问题是由于某种原因我拥有的公式看不到表单输入到该单元格的数据。所有其他单元格数据都会填充,并且可以通过我用来测试它的各种其他公式看到。只是数量单元格。
答案 0 :(得分:0)
这是我怀疑正在发生的事情:用户表单上的输入TextBox
包含String
。这就是他们所能包含的全部。您正在尝试将字符串转换为数字:
Private Sub Transaction_Qty_Box_AfterUpdate()
On Error Resume Next
Me.Transaction_Qty_Box.Value = CDec(Me.Transaction_Qty_Box.Value)
'Confirm my suspicions:
MsgBox TypeName(Me.Transaction_Qty_Box.Value)
End Sub
但是随后您要将那个Decimal
实例传递回TextBox.Value
,这将它隐式地转换回String
。
所以,您有个正确的主意,但我想您在错误的地方进行了。尝试在此处投射:
table_object_row.Range(1, 6).Value = CDec(Me.Transaction_Qty_Box)
请注意,这已经是您使用Me.DateBox
所做的事情:
table_object_row.Range(1, 1).Value = CDate(Me.Date_Box)
您可能可以删除_AfterUpdate
事件处理程序,而只需将文本框值转储到工作表即可。根据需要投放它们,并根据需要将格式直接应用于单元格。