VBA运行时错误’91’用于Excel工作表导入。

huangapple go评论161阅读模式
英文:

VBA run-time error '91' for excel worksheet imports

问题

以下是您提供的 VBA 代码的中文翻译:

选项 显式
Sub IMPORT()
'声明变量
Dim job As String
Dim engrdue, dftdue As String
Dim engrout, dftout As String
Dim engr, drafter As String
Dim tosales, PM As String
Dim loaddate, shopdate As String
Dim detailer As String
Dim rapp As String
Dim atype As String
Dim edwgs As String
Dim earlyab As String
Dim i As Integer
Dim AB As String
Dim abreq As String
Dim rng As Range
Dim rng2 As Range
Dim rng3 As Range
Dim result As Range
'清除单元格内容
Workbooks("PROJECT MANAGEMENT MATRIX A.xlsm").Worksheets("MASTER SCHEDULE").Range("B2", "F40").ClearContents
Workbooks("PROJECT MANAGEMENT MATRIX A.xlsm").Worksheets("MASTER SCHEDULE").Range("H2", "I40").ClearContents
Workbooks("PROJECT MANAGEMENT MATRIX A.xlsm").Worksheets("MASTER SCHEDULE").Range("J2", "J40").ClearContents
Workbooks("PROJECT MANAGEMENT MATRIX A.xlsm").Worksheets("MASTER SCHEDULE").Range("P2", "P40").ClearContents
Workbooks("PROJECT MANAGEMENT MATRIX A.xlsm").Worksheets("MASTER SCHEDULE").Range("O2", "O40").ClearContents
Workbooks("PROJECT MANAGEMENT MATRIX A.xlsm").Worksheets("MASTER SCHEDULE").Range("N2", "N40").ClearContents
Workbooks("PROJECT MANAGEMENT MATRIX A.xlsm").Worksheets("MASTER SCHEDULE").Range("L2", "L40").ClearContents
Workbooks("PROJECT MANAGEMENT MATRIX A.xlsm").Worksheets("MASTER SCHEDULE").Range("M2", "M40").ClearContents
Workbooks("PROJECT MANAGEMENT MATRIX A.xlsm").Worksheets("MASTER SCHEDULE").Range("K2", "K40").ClearContents
'打开 ASI 主排程工作簿
Workbooks.Open ("S:\Scheduling\ASI Master Schedule\ASI Master Schedule.xlsx")
Workbooks.Open ("S:\Drafting_Detailing\CCCCC_\CCCCC99.xls")
Workbooks.Open ("S:\Scheduling\ASI Master Schedule\DAILYTONNAGELOG.xls")
'设置变量
For i = 2 To 40
job = Workbooks("PROJECT MANAGEMENT MATRIX A.xlsm").Worksheets("MASTER SCHEDULE").Cells(i, "A") '作业值保存为第 i 行,列 A
Set rng = Workbooks("ASI Master Schedule.xlsx").Worksheets("Master Schedule").Range("R:R").Find(job) '在主排程中查找作业值
Set rng2 = Workbooks("CCCCC99.xls").Worksheets("JOB INFO").Range("A:A").Find(job)
Set rng3 = Workbooks("DAILYTONNAGELOG.xls").Worksheets("Archive").Range("A:A").Find(job) '在 DAILYTONNAGELOG 中查找作业值
tosales = Workbooks("ASI Master Schedule.xlsx").Worksheets("Master Schedule").Cells(rng.Row, "CH") '从主排程中获取 TO SALES 值
PM = Workbooks("ASI Master Schedule.xlsx").Worksheets("Master Schedule").Cells(rng.Row, "BH") '从主排程中获取 PM 值
loaddate = Workbooks("ASI Master Schedule.xlsx").Worksheets("Master Schedule").Cells(rng.Row, "L") '从主排程中获取 LOAD DATE 值
shopdate = Workbooks("ASI Master Schedule.xlsx").Worksheets("Master Schedule").Cells(rng.Row, "DD") '从主排程中获取 SHOP DATE 值
detailer = Workbooks("ASI Master Schedule.xlsx").Worksheets("Master Schedule").Cells(rng.Row, "DB") '从主排程中获取 DETAILER 值
rapp = Workbooks("ASI Master Schedule.xlsx").Worksheets("Master Schedule").Cells(rng.Row, "CW") '从主排程中获取 RETURNED APPROVALS DATE 值
engrdue = Workbooks("ASI Master Schedule.xlsx").Worksheets("Master Schedule").Cells(rng.Row, "CJ") '从主排程中获取 ENGINEERING DUE DATE 值
engrout = Workbooks("ASI Master Schedule.xlsx").Worksheets("Master Schedule").Cells(rng.Row, "CK") '从主排程中获取 ENGINEERING RELEASE DATE 值
engr = Workbooks("ASI Master Schedule.xlsx").Worksheets("Master Schedule").Cells(rng.Row, "CL") '从主排程中获取 ENGINEER 值
dftdue = Workbooks("ASI Master Schedule.xlsx").Worksheets("Master Schedule").Cells(rng.Row, "CN") '从主排程中获取 DRAFTING DUE DATE 值
dftout = Workbooks("ASI Master Schedule.xlsx").Worksheets("Master Schedule").Cells(rng.Row, "CO") '从主排程中获取 DRAFTING RELEASE DATE 值
drafter = Workbooks("ASI Master Schedule.xlsx").Worksheets("Master Schedule").Cells(rng.Row, "CP") '从主排程中获取 DRAFTER 值
AB = Workbooks("CCCCC99.xls").Worksheets("JOB INFO").Cells(rng2.Row, "X") '从 CCCCC 中获取 AB 日期值
atype = Workbooks("CCCCC99.xls").Worksheets("JOB INFO").Cells(rng2.Row, "AC") '从 CCCCCC99 中获取 RETURNED APPROVALS TYPE 值
edwgs = Workbooks("CCCCC99.xls").Worksheets("JOB INFO").Cells(rng2.Row, "Y") '从 CCCCCC99 中获取 ACTUAL DATE APPROVALS EMAILED 值
'将值放入目标工作表的相应单元格
Workbooks("PROJECT MANAGEMENT MATRIX A.xlsm").Worksheets("MASTER SCHEDULE").Cells(i, "B") = tosales '将 TO SALES 放入第 i 行,列 B
Workbooks("PROJECT MANAGEMENT MATRIX A.xlsm").Worksheets("MASTER SCHEDULE").Cells(i, "Q") = PM '将 PM 放入第 i 行,列 Q
Workbooks("PROJECT MANAGEMENT MATRIX A.xlsm").Worksheets("MASTER SCHEDULE").Cells(i, "P") = loaddate '将 LOAD DATE 放入第 i 行,列 P
Workbooks("PROJECT MANAGEMENT MATRIX A.xlsm").Worksheets("MASTER SCHEDULE").Cells(i, "O") = shopdate '将 SHOP DATE 放入第 i 行,列 O
Workbooks("PROJECT MANAGEMENT MATRIX A.xlsm").Worksheets("MASTER SCHEDULE").Cells(i, "N") = detailer '将 DETAILER 初始值放入第 i 行,列 N
Workbooks("PROJECT MANAGEMENT MATRIX A.xlsm").Worksheets("MASTER SCHEDULE").Cells(i, "L") =
<details>
<summary>英文:</summary>
I am attempting to pull cell data from a few different referenced excel workbooks. I am fairly new to VBA so my code is probably unnecessarily long, but everything works just fine until one of the referenced cells do not exist. At that point, it gives me the 91 error. What I would like to accomplish is this. When a value from the worksheet that I reference does not exist, I would like the program to skip that reference and continue on to the next row. When I use error handling, it actually copies the row above into the row with the missing data which is less than optimal. How do I accomplish this to have it just skip and leave the cells in the destination worksheet blank, or even better, have it put &quot;No data&quot;?
This is the code that I currently use.
```lang-vb
Option Explicit
Sub IMPORT()
&#39;DECLARE VARIABLES
Dim job As String
Dim engrdue, dftdue As String
Dim engrout, dftout As String
Dim engr, drafter As String
Dim tosales, PM As String
Dim loaddate, shopdate As String
Dim detailer As String
Dim rapp As String
Dim atype As String
Dim edwgs As String
Dim earlyab As String
Dim i As Integer
Dim AB As String
Dim abreq As String
Dim rng As Range
Dim rng2 As Range
Dim rng3 As Range
Dim result As Range
&#39;CLEAR CELLS
Workbooks(&quot;PROJECT MANAGEMENT MATRIX A.xlsm&quot;).Worksheets(&quot;MASTER SCHEDULE&quot;).Range(&quot;B2&quot;, &quot;F40&quot;).ClearContents
Workbooks(&quot;PROJECT MANAGEMENT MATRIX A.xlsm&quot;).Worksheets(&quot;MASTER SCHEDULE&quot;).Range(&quot;H2&quot;, &quot;I40&quot;).ClearContents
Workbooks(&quot;PROJECT MANAGEMENT MATRIX A.xlsm&quot;).Worksheets(&quot;MASTER SCHEDULE&quot;).Range(&quot;J2&quot;, &quot;J40&quot;).ClearContents
Workbooks(&quot;PROJECT MANAGEMENT MATRIX A.xlsm&quot;).Worksheets(&quot;MASTER SCHEDULE&quot;).Range(&quot;P2&quot;, &quot;P40&quot;).ClearContents
Workbooks(&quot;PROJECT MANAGEMENT MATRIX A.xlsm&quot;).Worksheets(&quot;MASTER SCHEDULE&quot;).Range(&quot;O2&quot;, &quot;O40&quot;).ClearContents
Workbooks(&quot;PROJECT MANAGEMENT MATRIX A.xlsm&quot;).Worksheets(&quot;MASTER SCHEDULE&quot;).Range(&quot;N2&quot;, &quot;N40&quot;).ClearContents
Workbooks(&quot;PROJECT MANAGEMENT MATRIX A.xlsm&quot;).Worksheets(&quot;MASTER SCHEDULE&quot;).Range(&quot;L2&quot;, &quot;L40&quot;).ClearContents
Workbooks(&quot;PROJECT MANAGEMENT MATRIX A.xlsm&quot;).Worksheets(&quot;MASTER SCHEDULE&quot;).Range(&quot;M2&quot;, &quot;M40&quot;).ClearContents
Workbooks(&quot;PROJECT MANAGEMENT MATRIX A.xlsm&quot;).Worksheets(&quot;MASTER SCHEDULE&quot;).Range(&quot;K2&quot;, &quot;K40&quot;).ClearContents
&#39;OPEN THE ASI MASTER SCHEDULE WORKBOOK
Workbooks.Open (&quot;S:\Scheduling\ASI Master Schedule\ASI Master Schedule.xlsx&quot;)
Workbooks.Open (&quot;S:\Drafting_Detailing\CCCCC_\CCCCC99.xls&quot;)
Workbooks.Open (&quot;S:\Scheduling\ASI Master Schedule\DAILYTONNAGELOG.xls&quot;)
&#39;SET VARIABLES
For i = 2 To 40
job = Workbooks(&quot;PROJECT MANAGEMENT MATRIX A.xlsm&quot;).Worksheets(&quot;MASTER SCHEDULE&quot;).Cells(i, &quot;A&quot;)                 &#39;JOB VALUE SAVED AS ROW I, COLUMN A
Set rng = Workbooks(&quot;ASI Master Schedule.xlsx&quot;).Worksheets(&quot;Master Schedule&quot;).Range(&quot;R:R&quot;).Find(job)            &#39;FIND JOB VALUE IN MASTER SCHEDULE
Set rng2 = Workbooks(&quot;CCCCC99.xls&quot;).Worksheets(&quot;JOB INFO&quot;).Range(&quot;A:A&quot;).Find(job)
Set rng3 = Workbooks(&quot;DAILYTONNAGELOG.xls&quot;).Worksheets(&quot;Archive&quot;).Range(&quot;A:A&quot;).Find(job)                       &#39;FIND JOB VALUE IN DAILYTONNAGELOG
&#39;        If IsEmpty(job) Then
&#39;        If rng Is Nothing Then
&#39;        If rng Is Not Nothing Then
&#39;        If [cell] is nothing then
&#39;        If [cell] Is Not Nothing Then
&#39;        If Not IsError(job) Then
&#39;        If Not IsError(rng) Then
&#39;        If Not IsError(rng2) Then
&#39;        If Not IsError(rng3) Then
&#39;        If Not IsError(&quot;ASI Master Schedule.xlsx&quot;) Then
&#39;        If Not IsError(rng.Row, &quot;CH&quot;) Then
&#39;            GoTo TheEnd
&#39;       Else
tosales = Workbooks(&quot;ASI Master Schedule.xlsx&quot;).Worksheets(&quot;Master Schedule&quot;).Cells(rng.Row, &quot;CH&quot;)      &#39;GRAB TO SALES FROM MASTER SCHEDULE
PM = Workbooks(&quot;ASI Master Schedule.xlsx&quot;).Worksheets(&quot;Master Schedule&quot;).Cells(rng.Row, &quot;BH&quot;)           &#39;GRAB TO SALES FROM MASTER SCHEDULE
loaddate = Workbooks(&quot;ASI Master Schedule.xlsx&quot;).Worksheets(&quot;Master Schedule&quot;).Cells(rng.Row, &quot;L&quot;)      &#39;GRAB LOAD DATE FROM MASTER SCHEDULE
shopdate = Workbooks(&quot;ASI Master Schedule.xlsx&quot;).Worksheets(&quot;Master Schedule&quot;).Cells(rng.Row, &quot;DD&quot;)     &#39;GRAB SHOPPED DATE FROM MASTER SCHEDULE
detailer = Workbooks(&quot;ASI Master Schedule.xlsx&quot;).Worksheets(&quot;Master Schedule&quot;).Cells(rng.Row, &quot;DB&quot;)     &#39;GRAB DETAILER NAME FROM MASTER SCHEDULE
rapp = Workbooks(&quot;ASI Master Schedule.xlsx&quot;).Worksheets(&quot;Master Schedule&quot;).Cells(rng.Row, &quot;CW&quot;)         &#39;GRAB RETURNED APPROVALS DATE FROM MASTER SCHEDULE
engrdue = Workbooks(&quot;ASI Master Schedule.xlsx&quot;).Worksheets(&quot;Master Schedule&quot;).Cells(rng.Row, &quot;CJ&quot;)      &#39;GRAB ENGINEERING DUE DATE FROM MASTER SCHEDULE
engrout = Workbooks(&quot;ASI Master Schedule.xlsx&quot;).Worksheets(&quot;Master Schedule&quot;).Cells(rng.Row, &quot;CK&quot;)      &#39;GRAB ENGINEERING RELEASE DATE FROM MASTER SCHEDULE
engr = Workbooks(&quot;ASI Master Schedule.xlsx&quot;).Worksheets(&quot;Master Schedule&quot;).Cells(rng.Row, &quot;CL&quot;)         &#39;GRAB ENGINEER FROM MASTER SCHEDULE
dftdue = Workbooks(&quot;ASI Master Schedule.xlsx&quot;).Worksheets(&quot;Master Schedule&quot;).Cells(rng.Row, &quot;CN&quot;)       &#39;GRAB DRAFTING DUE DATE FROM MASTER SCHEDULE
dftout = Workbooks(&quot;ASI Master Schedule.xlsx&quot;).Worksheets(&quot;Master Schedule&quot;).Cells(rng.Row, &quot;CO&quot;)       &#39;GRAB DRAFTING RELEASE DATE FROM MASTER SCHEDULE
drafter = Workbooks(&quot;ASI Master Schedule.xlsx&quot;).Worksheets(&quot;Master Schedule&quot;).Cells(rng.Row, &quot;CP&quot;)      &#39;GRAB DRAFTER FROM MASTER SCHEDULE
AB = Workbooks(&quot;CCCCC99.xls&quot;).Worksheets(&quot;JOB INFO&quot;).Cells(rng2.Row, &quot;X&quot;)                               &#39;GRAB AB DATE FROM CCCCC
atype = Workbooks(&quot;CCCCC99.xls&quot;).Worksheets(&quot;JOB INFO&quot;).Cells(rng2.Row, &quot;AC&quot;)                           &#39;GRAB RETURNED APPROVALS TYPE FROM CCCCCC99
edwgs = Workbooks(&quot;CCCCC99.xls&quot;).Worksheets(&quot;JOB INFO&quot;).Cells(rng2.Row, &quot;Y&quot;)                            &#39;GRAB ACTUAL DATE APPROVALS EMAILED FROM CCCCCC99
Workbooks(&quot;PROJECT MANAGEMENT MATRIX A.xlsm&quot;).Worksheets(&quot;MASTER SCHEDULE&quot;).Cells(i, &quot;B&quot;) = tosales     &#39;PUT NTP DATE IN ROW i, COLUMN B
Workbooks(&quot;PROJECT MANAGEMENT MATRIX A.xlsm&quot;).Worksheets(&quot;MASTER SCHEDULE&quot;).Cells(i, &quot;Q&quot;) = PM          &#39;PUT PM IN ROW i, COLUMN Q
Workbooks(&quot;PROJECT MANAGEMENT MATRIX A.xlsm&quot;).Worksheets(&quot;MASTER SCHEDULE&quot;).Cells(i, &quot;P&quot;) = loaddate    &#39;PUT LOAD DATE IN ROW i, COLUMN P
Workbooks(&quot;PROJECT MANAGEMENT MATRIX A.xlsm&quot;).Worksheets(&quot;MASTER SCHEDULE&quot;).Cells(i, &quot;O&quot;) = shopdate    &#39;PUT SHOP DATE IN ROW i, COLUMN O
Workbooks(&quot;PROJECT MANAGEMENT MATRIX A.xlsm&quot;).Worksheets(&quot;MASTER SCHEDULE&quot;).Cells(i, &quot;N&quot;) = detailer    &#39;PUT DETAILER INITIALS IN ROW i, COLUMN N
Workbooks(&quot;PROJECT MANAGEMENT MATRIX A.xlsm&quot;).Worksheets(&quot;MASTER SCHEDULE&quot;).Cells(i, &quot;L&quot;) = rapp        &#39;PUT RETURNED APPROVALS DATE ROW i, COLUMN L
Workbooks(&quot;PROJECT MANAGEMENT MATRIX A.xlsm&quot;).Worksheets(&quot;MASTER SCHEDULE&quot;).Cells(i, &quot;M&quot;) = atype       &#39;PUT RETURNED APPROVALS TYPE ROW i, COLUMN M
Workbooks(&quot;PROJECT MANAGEMENT MATRIX A.xlsm&quot;).Worksheets(&quot;MASTER SCHEDULE&quot;).Cells(i, &quot;C&quot;) = engrdue     &#39;PUT ENGR DUE DATE IN ROW i, COLUMN C
Workbooks(&quot;PROJECT MANAGEMENT MATRIX A.xlsm&quot;).Worksheets(&quot;MASTER SCHEDULE&quot;).Cells(i, &quot;D&quot;) = engrout     &#39;PUT ENGR RELEASE DATE IN ROW i, COLUMN D
Workbooks(&quot;PROJECT MANAGEMENT MATRIX A.xlsm&quot;).Worksheets(&quot;MASTER SCHEDULE&quot;).Cells(i, &quot;E&quot;) = engr        &#39;PUT ENGINEER IN ROW i, COLUMN E
Workbooks(&quot;PROJECT MANAGEMENT MATRIX A.xlsm&quot;).Worksheets(&quot;MASTER SCHEDULE&quot;).Cells(i, &quot;F&quot;) = dftdue      &#39;PUT DFT DUE DATE IN ROW i, COLUMN F
Workbooks(&quot;PROJECT MANAGEMENT MATRIX A.xlsm&quot;).Worksheets(&quot;MASTER SCHEDULE&quot;).Cells(i, &quot;H&quot;) = AB          &#39;PUT AB RELEASE DATE IN ROW i, COLUMN H
Workbooks(&quot;PROJECT MANAGEMENT MATRIX A.xlsm&quot;).Worksheets(&quot;MASTER SCHEDULE&quot;).Cells(i, &quot;I&quot;) = dftout      &#39;PUT DFT RELEASE DATE IN ROW i, COLUMN I
Workbooks(&quot;PROJECT MANAGEMENT MATRIX A.xlsm&quot;).Worksheets(&quot;MASTER SCHEDULE&quot;).Cells(i, &quot;J&quot;) = drafter     &#39;PUT DRAFTER IN ROW i, COLUMN J
Workbooks(&quot;PROJECT MANAGEMENT MATRIX A.xlsm&quot;).Worksheets(&quot;MASTER SCHEDULE&quot;).Cells(i, &quot;K&quot;) = edwgs       &#39;PUT ACTUAL DATE APPROVALS EMAILED IN ROW i, COLUMN K
&#39;End If
Next i
&#39;TheEnd:
End Sub

答案1

得分: 3

以下是代码的翻译部分:

Option Explicit
Sub IMPORT()
Dim wsMaster As Worksheet, addr
Dim wbASI As Workbook, wb99 As Workbook, wbTonnage As Workbook
Dim wsASI As Worksheet, ws99 As Worksheet, wsTonnage As Worksheet
Dim i As Long
Dim job As String, c As Range, addr
Dim jobRow1, jobRow2, jobRow3
Set wsMaster = ThisWorkbook.Worksheets("MASTER SCHEDULE")
'清除之前的数据
For Each addr in Array("B2:F2","H2:P2")
wsMaster.Range(addr).Resize(39).ClearContents
Next addr
'打开工作簿并分配工作表变量
Set wbASI = Workbooks.Open("S:\Scheduling\ASI Master Schedule\ASI Master Schedule.xlsx")
Set wsASI = wbASI.Worksheets("Master Schedule")
Set wb99 = Workbooks.Open("S:\Drafting_Detailing\CCCCC_\CCCCC99.xls")
Set ws99 = wb99.Worksheets("JOB INFO")
Set wbTonnage = Workbooks.Open("S:\Scheduling\ASI Master Schedule\DAILYTONNAGELOG.xls")
Set wsTonnage = wbTonnage.Worksheets("Archive")
'传输数据以及查找
For i = 2 To 40
job = wsMaster.Cells(i, "A").Value
'获取与此工作匹配的行(或如果没有匹配则返回错误值)
jobRow1 = Application.Match(job, wsASI.Range("R:R"), 0)
jobRow2 = Application.Match(job, ws99.Range("A:A"), 0)
jobRow3 = Application.Match(job, wsTonnage.Range("A:A"), 0)
With wsMaster.Rows(i)
.Columns("B").Value = Fetch(wsASI, jobRow1, "CH")   'NTP DATE
'...
'等等
'...
.Columns("F").Value = Fetch(wsASI, jobRow1, "CP")   'DFT DUE DATE
.Columns("H").Value = Fetch(ws99, jobRow2, "X")     'AB RELEASE DATE
'....
.Columns("K").Value = Fetch(ws99, jobRow2, "Y")     'ACTUAL DATE APPROVALS EMAILED
End With
Next i
End Sub
'如果`rw`不是错误值,则返回工作表`ws`、行`rw`和列`col`中的值;否则返回"No data"
Function Fetch(ws As Worksheet, rw As Variant, col As String)
If Not IsError(rw) Then
Fetch = ws.Cells(rw, col).Value
Else
Fetch = "No data"
End If
End Function

希望这有所帮助!

英文:

A few suggestion below for how you can improve things:

Option Explicit
Sub IMPORT()
Dim wsMaster As Worksheet, addr
Dim wbASI As Workbook, wb99 As Workbook, wbTonnage As Workbook
Dim wsASI As Worksheet, ws99 As Worksheet, wsTonnage As Worksheet
Dim i As Long
Dim job As String, c As Range, addr
Dim jobRow1, jobRow2, jobRow3
Set wsMaster = ThisWorkbook.Worksheets(&quot;MASTER SCHEDULE&quot;)
&#39;clear previous
For Each addr in Array(&quot;B2:F2&quot;,&quot;H2:P2&quot;)
wsMaster.Range(addr).Resize(39).ClearContents
Next addr
&#39;open workbooks and assign worksheet variables
Set wbASI = Workbooks.Open(&quot;S:\Scheduling\ASI Master Schedule\ASI Master Schedule.xlsx&quot;)
Set wsASI = wbASI.Worksheets(&quot;Master Schedule&quot;)
Set wb99 = Workbooks.Open(&quot;S:\Drafting_Detailing\CCCCC_\CCCCC99.xls&quot;)
Set ws99 = wb99.Worksheets(&quot;JOB INFO&quot;)
Set wbTonnage = Workbooks.Open(&quot;S:\Scheduling\ASI Master Schedule\DAILYTONNAGELOG.xls&quot;)
Set wsTonnage = wbTonnage.Worksheets(&quot;Archive&quot;)
&#39;transfer data along with lookups
For i = 2 To 40
job = wsMaster.Cells(i, &quot;A&quot;).Value
&#39;get matching row for this job (or error value if no match)
jobRow1 = Application.Match(job, wsASI.Range(&quot;R:R&quot;), 0)
jobRow2 = Application.Match(job, ws99.Range(&quot;A:A&quot;), 0)
jobRow3 = Application.Match(job, wsTonnage.Range(&quot;A:A&quot;), 0)
With wsMaster.Rows(i)
.Columns(&quot;B&quot;).Value = Fetch(wsASI, jobRow1, &quot;CH&quot;)   &#39;NTP DATE
&#39;...
&#39;etc
&#39;...
.Columns(&quot;F&quot;).Value = Fetch(wsASI, jobRow1, &quot;CP&quot;)   &#39;DFT DUE DATE
.Columns(&quot;H&quot;).Value = Fetch(ws99, jobRow2, &quot;X&quot;)     &#39;AB RELEASE DATE
&#39;....
.Columns(&quot;K&quot;).Value = Fetch(ws99, jobRow2, &quot;Y&quot;)     &#39;ACTUAL DATE APPROVALS EMAILED
End With
Next i
End Sub
&#39;If `rw` is not an error value, return value from worksheet `ws`,
&#39; row `rw` and column `col`; else return &quot;No data&quot;
Function Fetch(ws As Worksheet, rw As Variant, col As String)
If Not IsError(rw) Then
Fetch = ws.Cells(rw, col).Value
Else
Fetch = &quot;No data&quot;
End If
End Function

huangapple
  • 本文由 发表于 2023年7月14日 02:38:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76682359.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定