首页 > 解决方案 > VBA子没有进入功能

问题描述

我在 Excel 工作簿的不同工作表中创建了以下函数,它们都由子执行。但是,当我启动子程序时,它不会访问函数并直接跳过If语句。

Sheet1 功能:

Public Function ndg(row As Range) As Integer
    ndg = Range("b" & row).Value    
End Function

Function Checkispraticaforeclosure(row As Range)
   Dim ndga As Integer
   Dim rowindex As Integer
   ndga = ndg(row)
   rowindex = Sheet6.findrownumberndg(ndga)

   If Sheet6.ispositionforeclosure(rowindex) = True Then
       row.Cells(33) = Sheet6.getforeclosurecode(rowindex)
       Checkispraticaforeclosure = True
   Else
       Checkispraticaforeclosure = False
   End If
End Function

Sub insertcode(row As Range)
    Dim ndga As Integer
    Dim rowindex As Integer
    ndga = ndg(row)
    rowindex = Sheet6.findrownumberndg(ndga)

    If Sheet6.ispositionforeclosure(rowindex) = False Then    
        row.Cells(33) = "ok"
    End If
End Sub

Sheet6 功能:

Public Function findrownumberndg(ndg As Integer) As Integer
    Set foundcell = Sheet6.Range("a:a").Find(ndg, lookat:=xlWhole)

    If Not foundcell Is Nothing Then
        findrownumberndg = 0
    Else
        findrownumberndg = foundcell.row
    End If
End Function

Public Function ispositionforeclosure(row As Integer) As Boolean
    If Range("D" & row).Value = "Foreclosure procedure" Then
        ispositionforeclosure = True
    Else
        ispositionforeclosure = False
    End If
End Function

Public Function getforeclosurecode(row As Integer)    
    getforeclosurecode = Range("f" & row).Value
End Function

执行子:

Public Function sheet1lastrow()
lastrow = Sheet1.Cells(Rows.Count, "b").End(xlUp).row
End Function

Sub masterinsertcode()
    For x = 6 To ThisWorkbook.sheet1lastrow()
        Dim checked
        checked = False
        Dim currentrow As Range
        Set currentrow = Sheet1.Rows(x)

        checked = Sheet1.Checkispraticaforeclosure(currentrow)

        If checked = False Then
            Sheet1.insertcode (currentrow)
        End If
    Next
End Sub

我不确定为什么执行子没有进入我创建的检查并直接转到End Sub.

标签: excelvba

解决方案


推荐阅读