宏插入零

时间:2014-05-20 18:21:46

标签: excel-vba vba excel

非常感谢任何帮助。这个excel vb脚本在名为&#34的订单中搜索X或x;订单表-SL"然后将特定单元格值插入新工作表。除了在实际值

的新工作表插入中插入0(零)之外,它运行良好

源代码:

Sub SOLIMPORT2(worksheetname As String)
    Dim Order As Worksheet
    Dim SolomonImport As Worksheet

    Set Order = Worksheets("Order sheet -SL")
    Set SolomonImport = Worksheets(worksheetname)


    Dim i As Integer
    Dim j As Integer

    i = 8
    j = 3




    Do
        If Order.Cells(i, 6) = "x" Or Order.Cells(i, 6) = "X" Then
            SolomonImport.Range("A1") = "LEVEL0"
            SolomonImport.Range("B1") = "SO #:"
            SolomonImport.Range("C1") = "PSO"
            SolomonImport.Range("A3") = "LEVEL1"
            SolomonImport.Cells(j, 2) = Order.Cells(i, 11)
            SolomonImport.Cells(j, 3) = Order.Cells(i, 13)
            'Range("I10").Value = Range("F10").Value

            SolomonImport.Cells(j, 4) = Order.Cells(i, 14)
            SolomonImport.Cells(j, 5) = Order.Cells(i, 15)
            'SolomonImport.Cells(j, 31) = Order.Range("F1")
            'SolomonImport.Cells(j, 32) = "TC-50"
            'SolomonImport.Cells(j, 3) = Order.Cells(i, 11)
            'SolomonImport.Cells(j, 5) = "0"
            'SolomonImport.Cells(j, 13) = "0"
            'SolomonImport.Cells(j, 37) = Order.Cells(i, 8)
            'SolomonImport.Cells(j, 38) = Order.Cells(i, 10)

            j = j + 1
        End If

        i = i + 1

        If Order.Range("A" & Trim(Str(i))) = "SHEET TAB Z" Then
            Exit Do
        End If
    Loop

End Sub

实施例: Ordered Sheet -SL选项卡包含源数据:

  1.    RELEASE    PART #      QUANTITY         UNIT COST       EXTENDED COST
    
       x          MX418 S/C     1              147.9           147.9
       x          MX418 D/C     4              178.5           714
       x          MX418 S/C     2              147.9       295.8
    
  2. 新工作表和输出:

    新工作表:上面的黄色突出显示的单元格显示为0。联合成本单元格包含此公式(= A!L9),扩展成本单元格公式为数量乘以单位成本。

    MX418 S/C   1   0   1
    
    MX418 D/C   4   0   0
    
    MX418 S/C   2   0   0
    

    谢谢。

1 个答案:

答案 0 :(得分:0)

看起来您的代码只是复制公式而不是原始工作表中的值。

尝试在每个.value的末尾添加order.cells(x,y)

即。 SolomonImport.Cells(j, 4) = Order.Cells(i, 14).value