除了在单元格中放置字符串外,一切似乎都有效

时间:2014-11-07 11:58:23

标签: excel excel-vba vba

此代码在假设时不会打印-10
但其他一切都很好。

它遍历两个列表:(Sheet1edi_partnere
当它被假定时退出循环。

问:我错过了什么:为什么没有cells().value抓住?

Do
    If orgnr1 = "" Then Exit Sub
    Do
        orgnr2 = Sheets("edi_partnere").Cells(j, 1).Value
        If orgnr2 = orgnr1 Then
            Sheets("Sheet1").Cells(j, 9).Value = "-1"           'not happening
            Exit Do
        ElseIf orgnr2 = "" Then
            Sheets("Sheet1").Cells(j, 9).Value = "0"            'not happening
            Exit Do
        Else: j = j + 1
        End If
    Loop
    i = i + 1
    orgnr1 = Sheets("Sheet1").Cells(i, 1).Value
Loop

1 个答案:

答案 0 :(得分:0)

我认为你必须重置变量j,所以我在代码中添加j = 0。

根据Siddharth Rout,如果没有设置orgnr1那么orgnr1 = Sheets(" Sheet1")。Cells(i,1).Value

Do
    If orgnr1 = "" Then Exit Sub  
  Do
    orgnr2 = Sheets("edi_partnere").Cells(j, 1).Value       
    If orgnr2 = orgnr1 Then       
        Sheets("Sheet1").Cells(j, 9).Value = "-1"           'not happening
        Exit Do       
    ElseIf orgnr2 = "" Then       
        Sheets("Sheet1").Cells(j, 9).Value = "0"            'not happening
        Exit Do            
    Else: j = j + 1
    End If           
  Loop   
  j = 0
  i = i + 1   
  orgnr1 = Sheets("Sheet1").Cells(i, 1).Value
Loop