两个工作簿之间的VBA交叉检查数据

时间:2018-12-25 22:35:12

标签: arrays excel vba formula cross-reference

我尝试了一些代码,但是我陷入了困境,Idea是拥有一个包含数据的工作表,其他工作表将具有报告部分,然后创建PDF;我添加了一个部分,它将发现一个通用名称是一个由大名和数字组成的文件,然后将计算具有90天以上的日期,这是进入PDF工作表的结果。在“数据”工作簿中,有一个列,我相信该列的结果将有助于编写代码,如果数字低于3,则结果为“非当前”以促进可视化。某些代码仍带有'作为自注释,希望可以帮助任何人。

Sub Checkcurrency()
Application.ScreenUpdating = False

'Possibly lots of DIM and SET overused; needs a revision

Dim FC As Worksheet
Dim DT As Worksheet
Dim FP As Workbook
Dim ML As Worksheet
Dim FD As Workbook
Dim dat As Worksheet

Dim l As Variant
Dim c As Variant 'crew 3 letter code
Dim d As Variant
Dim li As Long

Dim r As Long
Dim cn As Variant 'crew name
Dim tri As Variant
Dim ro As Long
Dim lig As Long
Dim mln As Variant
Dim nam As Variant
Dim col As Long

Dim CR As Worksheet
Dim CD As Worksheet

Set CR = Sheets("Crew")
Set CD = Sheets("Crew details sheet")

    Set FD = Workbooks.Open(Filename:=ThisWorkbook.Path & "\" & "flight data.xlsm")
    Set nam = Sheets("data").Range("BX3:BX5000").Find(CR.Range("A9"))

    col = nam.Row
    Set dat = Sheets("data")

'    Selection.Formula = "=IF(OR((""A"" & col)>(TODAY()-90);(""CA"" & col)<3);""Not Current"";(""A"" & col)+90)"

    If dat.Range("BX" & col).Value = CR.Range("A9") Then

    CD.Range("O36") = dat.Range("CA" & col).Value  'Night Currency
    CD.Range("O37") = dat.Range("BZ" & col).Value '90day currency

End If
Application.ScreenUpdating = True

FD.Close savechanges:=True


End Sub

这是吸引我的部分

Set FD = Workbooks.Open(Filename:=ThisWorkbook.Path & "\" & "flight data.xlsm")
Set nam = Sheets("data").Range("BX3:BX5000").Find(CR.Range("A9"))

col = nam.Row
Set dat = Sheets("data")
'    Selection.Formula = "=IF(OR((""A"" & col)>(TODAY()-90);(""CA"" & col)<3);""Not Current"";(""A"" & col)+90)"
If dat.Range("BX" & col).Value = CR.Range("A9") Then

CD.Range("O36") = dat.Range("CA" & col).Value  'Night Currency
CD.Range("O37") = dat.Range("BZ" & col).Value '90day currency

感谢您的帮助。

0 个答案:

没有答案