运行时错误1004.单元格不完全合格我假设

时间:2017-03-07 22:15:34

标签: excel vba excel-vba

马上,我对VBA并不陌生,除了阻止我继续下去之外,下面的代码可能会出现错误。基本上我正在尝试使用工作簿中的各种其他工作表中的数据构建一个树(与BOM不同)。以下是我的代码:

Private Sub CommandButton1_Click()

Dim acreg As String, eonum As String
Dim wb As Workbook, wsrpt As Range
Dim wsgr As Range, wsassy As Range, wspd As Range


Dim i As Integer, j As Integer, khor As Integer, x As Integer
Dim kvert As Integer, j2 As Integer

Dim parenttemp As String, childtemp As String

Set wb = ThisWorkbook

acreg = "EK-PPT"
eonum = "E-123-0"
Set wsgr = wb.Worksheets("GEN_ARR").UsedRange
Set wsassy = wb.Worksheets("ASSY").UsedRange
Set wspd = wb.Worksheets("PART_DETAIL").UsedRange
Set wsrpt = wb.Worksheets("REPORT").UsedRange

i = 1
j = 1
j2 = 1
khor = 3
kvert = 1
x = 1

While wsgr(Cells(i, 2)).Value <> ""
If wsgr(Cells(i, 2)).Value = eonum And wsgr(Cells(i, 5)).Value = acreg Then
    parenttemp = wsgr(Cells(i, 1)).Value
    wsrpt(Cells(khor, kvert)).Value = parenttemp
    kvert = kvert + 1
    i = i + 1

    While wsassy(Cells(j, 1)).Value <> ""
        If wsassy(Cells(j, 2)).Value = parenttemp Then
                childtemp = wsassy(Cells(j, 1)).Value
                wsrpt(Cells(khor, kvert)).Value = childtemp
                parenttemp = childtemp
                kvert = kvert + 1
                j = j + 1

            While wsassy(Cells(j2, 1)).Value <> ""
            If wsassy(Cells(j2, 2)).Value = parenttemp Then
                childtemp = wsassy(Cells(j2, 1)).Value
                wsrpt(Cells(khor, kvert)).Value = childtemp
                parenttemp = childtemp
                kvert = kvert + 1
                j2 = 1
            Else
                j2 = j2 + 1
            End If
            Wend

            While wspd(Cells(x, 1)).Value <> ""
            If wspd(Cells(x, 2).Value) = childtemp Then
                childtemp = wspd(Cells(x, 1)).Value
                wsrpt(Cells(khor, kvert)).Value = childtemp
                khor = khor + 1
                x = x + 1
            Else
                x = x + 1
            End If
            Wend
        Else
            j = j + 1
        End If
        Wend

Else
    i = i + 1
End If
Wend


End Sub

我认为这是因为我的细胞因片材激活而无法完全合格。是否需要激活床单?或者我们可以指向这些细胞而不必激活?

任何帮助将不胜感激!谢谢!

0 个答案:

没有答案