我在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
。