mysql - VBA Excel 在不同工作表的表格中查找数据

标签 mysql vba excel

我有两个工作表,“接收”和“订单存档”,两个工作表上都有具有相同标题的表格:sku、数量、患者姓名、产品信息、供应商、L/R、临床医生、订购日期、采购订单号、已接收, 成本 。

我正在尝试编写一个从接收页表开始的宏,并提取在名为“OrderArchive”的订单存档表中找到的所有行,将该行信息复制到“接收”表中。不过,我只希望它提取在“已接收”列中指定为“[待处理]”的邮件。

最佳答案

通常不喜欢不费吹灰之力就将代码交给别人,但请尝试一下,让我知道这是否是您正在寻找的:

enter image description here

'I named the Receiving tab's table "receivingTable"
'I named the Order Archive tab's table "orderArchiveTable"

Dim cnt As Integer
Dim x As Integer
Dim y As Integer
Dim cntPending As Integer
Dim myArray() As Variant

'count number of rows that are in orderArchiveTable
cnt = Range("orderArchiveTable").Rows.Count

'Scan orderArchiveTable for 'Pending' Orders in the 'Received' column
cntPending = 0
For x = 1 To cnt

    'count number of row that are Pending to use for array size
    If Range("orderArchiveTable[Received]")(x).Value = "Pending" Then
        cntPending = cntPending + 1
    End If

Next x


If cntPending = 0 Then Exit Sub  'no pending orders


'ReDim array for correct size... remember that it starts at zero! NOT 1
ReDim myArray(cntPending - 1, 9)

'Fill array with values
y = 0
For x = 1 To cnt
    If Range("orderArchiveTable[Received]")(x).Value = "Pending" Then
        myArray(y, 0) = Range("orderArchiveTable[sku]")(x).Value
        myArray(y, 1) = Range("orderArchiveTable[qty]")(x).Value
        myArray(y, 2) = Range("orderArchiveTable[Patient Name]")(x).Value
        myArray(y, 3) = Range("orderArchiveTable[Vendor]")(x).Value
        myArray(y, 4) = Range("orderArchiveTable[L/R]")(x).Value
        myArray(y, 5) = Range("orderArchiveTable[Clinician]")(x).Value
        myArray(y, 6) = Range("orderArchiveTable[Date Ordered]")(x).Value
        myArray(y, 7) = Range("orderArchiveTable[PO Number]")(x).Value
        myArray(y, 8) = Range("orderArchiveTable[Received]")(x).Value
        myArray(y, 9) = Range("orderArchiveTable[Cost]")(x).Value

        'Not sure if you want to delete the rows taken, but you would do this here and subtract 1 from x and cnt
        Selection.ListObject.ListRows(x).Delete
        x = x - 1
        cnt = cnt - 1

        'go to next row in array
        y = y + 1
    End If
Next x

'count number of rows that are in receivingTable
cnt = Range("receivingTable").Rows.Count + 1

'Dump array into receivingTable
For x = 0 To UBound(myArray)
    Set NewRow = Range("receivingTable").ListObject.ListRows.Add(AlwaysInsert:=True)
    Range("receivingTable[sku]")(cnt + x).Value = myArray(x, 0)
    Range("receivingTable[qty]")(cnt + x).Value = myArray(x, 1)
    Range("receivingTable[Patient Name]")(cnt + x).Value = myArray(x, 2)
    Range("receivingTable[Vendor]")(cnt + x).Value = myArray(x, 3)
    Range("receivingTable[L/R]")(cnt + x).Value = myArray(x, 4)
    Range("receivingTable[Clinician]")(cnt + x).Value = myArray(x, 5)
    Range("receivingTable[Date Ordered]")(cnt + x).Value = myArray(x, 6)
    Range("receivingTable[PO Number]")(cnt + x).Value = myArray(x, 7)
    Range("receivingTable[Received]")(cnt + x).Value = myArray(x, 8)
    Range("receivingTable[Cost]")(cnt + x).Value = myArray(x, 9)
Next x

关于mysql - VBA Excel 在不同工作表的表格中查找数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38081769/

相关文章:

excel - 从列中的所有 URL 检索信息

vba - 如何在 Application.OnKey 中使用方括号? (Excel VBA)

arrays - 如何将变量值舍入到数组中的下一个最低数字?

c# - 以编程方式获取锁定 Excel 工作簿的用户

mysql - Mamp MySQL 无法在第二个 OS X 用户帐户中运行

mysql - MySQL phpmyadmin空表

mysql - Mysql - 从数据库日期创建分组数据列表

MySQL 触发插入/更新事件

vba - 字2010 : how to create a drop-down menu in qat (quick access toolbox)

excel - 如何使excel vba代码完全合格/如何规避运行时错误?