[英]Excel VBA form, how to submit multiple rows ONLY if the value in a certain cell in each row is larger than > 0
I am currently trying to create a data entry like form within Excel 2016 with VBA code and some formulas that enables the user to choose a product from a dropdown to automatically calculate quantities and order amounts needed for each raw material that makes up the product.我目前正在尝试使用 VBA 代码和一些公式在 Excel 2016 中创建一个类似表格的数据条目,这些公式使用户能够从下拉列表中选择产品,以自动计算构成产品的每种原材料所需的数量和订单金额。
My workbook is made up of 4 sheets titled我的工作簿由 4 张标题为
"iform" - A form that allows the user to select a product from a drop down, enter in a date and enter a qty. “iform” -允许用户从下拉列表中选择 select 产品、输入日期和数量的表单。 The form automatically then pulls the description of the product.然后表单会自动提取产品的描述。 Then in a table below all the required parts to make this product are listed with qty on hand, qty on order, allocated, qty needed for each 1 product and how many are required然后在下表中列出了制造该产品所需的所有零件,其中包括手头数量、订单数量、已分配、每 1 个产品所需的数量以及需要多少
"ordermaster" - A blank list that gets updated with requested parts and amounts whenever the user submits the form from "iform" , "ordermaster" -每当用户从 "iform" 提交表单时,都会使用请求的零件和金额更新空白列表,
"bomitemqty" - a list containing all the final products and their parts. “bomitemqty” -包含所有最终产品及其部件的列表。 Other information included in this list: current quantity on hand, quantity allocated and qty required per 1 final produced product此列表中包含的其他信息:当前手头数量、分配数量和每 1 个最终生产产品所需的数量
"fgmaster" - a list containing all the final products “fgmaster” -包含所有最终产品的列表
Everything seems to be working so far apart from the fact that when I submit the form from "iform" I cant seem to get it to only send rows where 'qty needed' > 0 to the list in "ordermaster".除了当我从“iform”提交表单时,我似乎无法让它只将“需要数量”> 0的行发送到“ordermaster”中的列表。 Screenshots and code provided below.下面提供的屏幕截图和代码。 The rows highlighted in yellow below are the ones im wanting to not move over to the list in "masterorder"下面以黄色突出显示的行是我不想移到“masterorder”列表中的行
Screenshot: iform image截图: iform 图像
The cells containing the all the parts and qty's are populated using the below formula (this data is pulled from "bomitemqty" using the fg num, circled in red above, to filter the required rows:使用以下公式填充包含所有零件和数量的单元格(此数据使用 fg num 从“bomitemqty”中提取,上面用红色圈出,以过滤所需的行:
=IFERROR(INDEX(bomitem[PartNum]:bomitem[qtyperunit], SMALL(IF(COUNTIF($G$6,bomitem), MATCH(ROW(bomitem), ROW(bomitem)), ""), ROWS(E$13:$E14)), COLUMNS(bomitemqty:$B$2,B3)),"--")
The qty needed is calculated using the below formula:所需数量使用以下公式计算:
=IFERROR((($L$8*J13)+I13)-(G13+H13),"")
When the user hits the save button the following module is executed and data from "iform" is moved to a list in the sheet "masterorder" screenshot and code below (the rows highlighted in yellow in the below screenshot and the ones im wanting to not move across)当用户点击保存按钮时,执行以下模块并将“iform”中的数据移动到工作表“masterorder”屏幕截图和下面的代码中的列表(下面的屏幕截图中以黄色突出显示的行和我不想跨过去)
Screenshot: "ordermaster" sheet with sample data submitted屏幕截图:提交了示例数据的“ordermaster”表
VBA Code: VBA 代码:
Sub Save()
Set frm = ThisWorkbook.Sheets("iform")
Set Source = ThisWorkbook
Dim Var1 As Integer
Dim Var2 As Integer
Dim Var3 As Integer
Set Wks = Source.Worksheets("iform")
Var1 = Application.WorksheetFunction.CountIf(Wks.Range("E13:E29"), "--")
Var2 = 17 - Var1
Var3 = 30 - Var2 - 1
Dim lr As Long, ws As Worksheet
Dim arr As Variant, i As Long
With Worksheets("iform")
lr = .Cells(30, "E").End(xlUp).Row - Var3
ReDim arr(1 To lr, 1 To 9)
For i = LBound(arr, 1) To UBound(arr, 1)
arr(i, 1) = ""
arr(i, 2) = ""
arr(i, 3) = .Cells(i + 12, "E").Value
arr(i, 4) = ""
arr(i, 5) = ""
arr(i, 6) = .Cells(i + 12, "L").Value
arr(i, 7) = .Cells(6, "L").Value
arr(i, 8) = ""
arr(i, 9) = [Text(Now(), "DD-MM-YYYY HH:MM:SS")]
Next i
End With
With Worksheets("ordermaster")
lr = .Range("C" & .Rows.count).End(xlUp).Row + 1
.Cells(lr, "A").Resize(UBound(arr, 1), UBound(arr, 2)) = arr
End With
End Sub
Option Explicit
Private Sub cmdSave_Click()私有子 cmdSave_Click()
Call Save
End Sub Private Sub Worksheet_SelectionChange(ByVal Target As Range) End Sub Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub结束子
VBasic2008 posted an answer in the comments above that solved my problem:)... VBasic2008 在上面的评论中发布了一个答案,解决了我的问题:)...
Right after For i =...
add the line If.Cells(i + 12, "L").Value > 0
Then and before Next i add the line End If
在 For i =...
之后添加行If.Cells(i + 12, "L").Value > 0
Then 和 Next 之前我添加行End If
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.