|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
因公司业务需要,我在开发自己的程序的时候,对原先的数据只需要在交易日列数据中找到最后一个交易日的行数即可,但是新的需求是,如果交易日列的数据中的交易日是乱序的,我需要先进行排序,然后找到最后一个交易日所在行。
问题出现在,我在对表格中的数据按时间排序完成后,无法对交易时间数据所在列使用Find方法,提示错误:运行时错误“1004”,应用程序定义或对象定义错误。
代码如下:
- With Workbooks(fileName).Worksheets(wst)
- .Range(sourceCol & 1).Sort key1:=.Range(tradingDateCol & 1).Value2, Order1:=xlAscending, Header:=xlYes
- lastRow = .Range(tradingDateCol).Find(What:=lastTradingDay, SearchOrder:=xlByRows, LookAt:=xlWhole).row '程序运行到这里出错
- For firstRow = 2 To lastRow
- If Not sourceDict.Exists(.Range(sourceCol & firstRow).Value2) Then
- GoTo continue
- End If
- GJDataFromProductionReport = .Range(GJDataCol & firstRow).Value2
- NmDataFromProductionReport = .Range(NmDataCol & firstRow).Value2
- '检查每天出入库数据
- If (GJDataFromProductionReport > 0 And NmDataFromProductionReport <= 0) Or (GJDataFromProductionReport <= 0 And NmDataFromProductionReport > 0) Then
- errorMessage = errorMessage & "逻辑有误。生产日报中" & .Range(sourceCol & firstRow).Value2 & "在" & .Range(tradingDateCol & firstRow).Value2 & "日,吉焦或立方米数据为0,但对应的吉焦数据不为0" & "/"
- ElseIf NmDataFromProductionReport <> 0 And .Range(sourceCol & firstRow).Value2 <> "xxx" Then
- coefficient = .Range(coefficientCol & firstRow).Value2
- If GJDataFromProductionReport / (NmDataFromProductionReport * 10) - coefficient > 0.015 Or GJDataFromProductionReport / (NmDataFromProductionReport * 10) - coefficient < -0.015 Then
- errorMessage = errorMessage & "在生产日报中" & Application.WorksheetFunction.Text(.Range(tradingDateCol & firstRow).Value2, "yyyy-mm-dd") & .Range(sourceCol & firstRow).Value2 & "万方转吉焦数不一致,两者相差" & NmDataFromProductionReport * 10000 * coefficient / 1000 - GJDataFromProductionReport & "/"
- End If
- End If
- continue:
- Next firstRow
- End With
复制代码
|
|