在我的代码中,在调用该代码所驻留的函数之前,我有一些错误编码。我认为'Dur节中有一些东西破坏了该函数,因为当最后一个gFindInColumn(sStr, Range("C3:C" & lRow))
被调用时,可以单步执行ok函数,它甚至可以获取我想要的数据,但是与其返回并放置到sRow(2,2)
中,不如返回到我的错误编码部分。
注意:我已注释掉整个Dur部分,因此sStr
包含与'Pre通过gFindInColumn
'Pre
dlgSysteEPatchTempDateTime.Show
temp = dlgSysteEPatchTempDateTime.txtBPreBaseLineEndTemp.Value
sStr = dlgSysteEPatchTempDateTime.txtBPreBaselineStartDate.Value & " " & dlgSysteEPatchTempDateTime.txtBPreBaselineStartTime.Value
eStr = dlgSysteEPatchTempDateTime.txtBPreBaselineEndDate.Value & " " & dlgSysteEPatchTempDateTime.txtBPreBaselineEndTime.Value
lRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "C").End(xlUp).row
sRow(1, 1) = gFindInColumn(sStr, Range("C3:C" & lRow))
eRow(1, 1) = gFindInColumn(eStr, Range("C3:C" & lRow))
'Call addFormulaTestDataLoop(temp, sRow(1, 1), eRow(1, 1))
'Dur
'temp = dlgSysteEPatchTempDateTime.txtBDurBaseLineEndTemp.Value
'sStr = dlgSysteEPatchTempDateTime.txtBDurBaselineStartDate.Value & " " & dlgSysteEPatchTempDateTime.txtBDurBaselineStartTime.Value
'eStr = dlgSysteEPatchTempDateTime.txtBDurBaselineEndtDate.Value & " " & dlgSysteEPatchTempDateTime.txtBDurBaselineEndTime.Value
'qtyDur = dlgSysteEPatchTempDateTime.txtDurQty.Value
'wsData.Activate
sRow(2, 2) = gFindInColumn(sStr, Range("C3:C" & lRow))
和
Public Function gFindInColumn(search As Variant, rngCol As Range, Optional rowNum As Long = 2) As Long
Dim f As Range
Set f = rngCol.Find(What:=search, After:=rngCol.Cells(rowNum), _
LookIn:=xlValues, LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
If Not f Is Nothing Then
'only return non-zero if the found cell is *after* rowNum
gFindInColumn = IIf(f.row > rowNum, f.row, 0)
Else
gFindInColumn = 0
End If
End Function