因此,我正在對一組數字文件進行審計,但我認爲我寫的方式非常複雜,所以也許有人可以幫助我...如何在不激活紙張的情況下引用紙張上的單元格?
我無法弄清楚爲什麼activesheet.cell工作正常,但是當我嘗試使用Workbooks(「Master List」)工作表(「Master Shipped」)單元格引用單元格時,它給了我一個錯誤。我已經用完整的文件位置嘗試過了,我用worksheets.cells試過了,我用sheets.cells試過了,我試過讓工作表變成一個變量,但是我無法使它工作。
它的工作,在那裏我命名變量的頂部,但它不工作,我的if語句這是我想要的工作,因爲我不想有激活片各10次循環。
Application.ScreenUpdating = False
LR = Cells(Rows.Count, 2).End(xlUp).Row
Dim AuditSheet As Worksheet, Mastersheet As Worksheet
Set AuditSheet = ThisWorkbook.Sheets("Audit")
Set Mastersheet = ThisWorkbook.Sheets("Master Shipped")
For r = 3 To LR
FpathBOL = "U:\Warehouse Associate\Shipped Orders 2016\Bill of Lading\"
fnamebol = Mastersheet.Cells(r, 21).Text
FNamePOD = Left(Mastersheet.Cells(r, 21).Text, (Len(Mastersheet.Cells(r, 21)) - 8))
FpathFile = "V:\LVA Files\" & Mastersheet.Cells(r, 4).Value & "\Line " & Mastersheet.Cells(r, 10).Value & "\"
FnameFile = Mastersheet.Cells(r, 4).Value & "-"
BOL = FpathBOL & "\" & fnamebol & ".pdf"
POD = FpathBOL & FNamePOD & "POD.pdf"
File1 = FpathFile & FnameFile & "PO.pdf"
File2 = FpathFile & FnameFile & "EIC PO.pdf"
File3 = FpathFile & FnameFile & "EDI 855.pdf"
File4 = FpathFile & FnameFile & "EDI 870.pdf"
File5 = FpathFile & FnameFile & "VENDOR INVOICE.pdf"
File6 = FpathFile & FnameFile & "EIC INVOICE.pdf"
File7 = FpathFile & FnameFile & "PCGR.pdf"
File8 = FpathFile & FnameFile & "PL.pdf"
File9 = FpathFile & FnameFile & "EDI.pdf"
If Dir(File1) = "" Then
Workbooks("Master List.xlsm").Worksheets("Audit").Activate
ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Activate
ActiveCell.Value = File1
End If
If Dir(File2) = "" Then
Worksheets("Audit").Activate
ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Activate
ActiveCell.Value = File2
End If
If Dir(File3) = "" And Dir(File9) = "" Then
Worksheets("Audit").Activate
ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Activate
ActiveCell.Value = File3
End If
If Dir(File4) = "" And Dir(File9) = "" Then
Worksheets("Audit").Activate
ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Activate
ActiveCell.Value = File4
End If
If Dir(File5) = "" Then
Worksheets("Audit").Activate
ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Activate
ActiveCell.Value = File5
End If
If Dir(File6) = "" Then
Worksheets("Audit").Activate
ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Activate
ActiveCell.Value = File6
End If
If Dir(File7) = "" Then
Worksheets("Audit").Activate
ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Activate
ActiveCell.Value = File7
End If
If Dir(File8) = "" Then
Worksheets("Audit").Activate
ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Activate
ActiveCell.Value = File8
End If
If Dir(BOL) = "" Then
Worksheets("Audit").Activate
ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Activate
ActiveCell.Value = FnameFile & BOL
End If
If Dir(POD) = "" Then
Worksheets("Audit").Activate
ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Activate
ActiveCell.Value = FnameFile & POD
End If
Next r
Application.ScreenUpdating = True
End Sub
閱讀,學習和愛情:怎樣避免使用'.Select' /'.Activate'](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select -in-Excel的VBA的宏)。 :D – BruceWayne
語法爲'Workbooks(「Master List.xlsm」)。Sheets(「Audit」)。Cells(1,1)'修改Cell'A1'。你也可以使用'Workbooks(「Master List.xlsm」)。表格(「Audit」)。Range(「A1」)' – user1274820