У меня есть файл, сохраненный в сети, к которому должны иметь доступ несколько человек Я добавил макрос, чтобы объединить данные из множества вкладок в одну (нужны несколько вкладок для организации), чтобы некоторые соединения работали намного эффективнее. Проблема в том, что примерно половина компьютеров, обращающихся к файлу, постоянно получает сообщение об ошибке Range - Method, и у меня нет доступа к этим компьютерам для отладки ...
Я прошел по коду, чтобы найти ошибку, но не могу найти одну ... хотя бы одну, которую я понимаю ...? Структура выглядит хорошо, насколько я могу судить ...
Dim i As Integer
Dim j As Integer
Dim MaxSheets As Integer
Dim wb As Workbook
Dim consolid As Worksheet
Dim summary As Worksheet
Dim PaidInv As Worksheet
Dim LRow As Long
Dim LInv As Long
Dim ConLRow As Long
'set initial values
Set wb = Workbooks("Wire Payments projections for Euro's")
Set consolid = wb.Sheets("Consolidation")
Set summary = wb.Sheets("Pay Summary")
Set PaidInv = wb.Sheets("Paid Invoices")
MaxSheets = Sheets.Count
LInv = 0
i = 1
j = 7
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
'clear values between a2 and last row
With consolid
ConLRow = .Range("A" & .Rows.Count).End(xlUp).Row
.Range("A2", .Cells(ConLRow, 7)).Clear
End With
For i = 1 To MaxSheets
'loop through all sheets except those named
If wb.Sheets(i).Name <> summary.Name And wb.Sheets(i).Name <> PaidInv.Name And wb.Sheets(i).Name <> consolid.Name Then
With wb.Sheets(i)
'Find last row on the sheet (for Search limiting)
LRow = .Range("B" & .Rows.Count).End(xlUp).Row + 1
'search for first empty cell between row 7 and last row on sheet
For j = 7 To LRow
If .Cells(j, 2).Value = "" And LInv = 0 Then
LInv = j
End If
Next j
End With
With consolid
'Find last used row
ConLRow = .Range("a" & .Rows.Count).End(xlUp).Row
'Assume LInv returned a value greater than 7, copy information to cells.
If LInv > 7 Then
.Range(.Cells(ConLRow + 1, 1), .Cells((ConLRow + (LInv - 7)), 1)) = wb.Sheets(i).Range("d1")
.Range(.Cells(ConLRow + 1, 2), .Cells((ConLRow + (LInv - 7)), 2)) = wb.Sheets(i).Range("b1")
wb.Sheets(i).Range(wb.Sheets(i).Cells(7, 2), wb.Sheets(i).Cells(LInv, 7)).Copy
consolid.Cells(ConLRow + 1, 3).PasteSpecial Paste:=xlPasteValues
End If
End With
End If
LInv = 0
Next i
'format columns and enter row headers
With consolid
.Columns(4).NumberFormat = "m/d/y"
.Columns(5).NumberFormat = "#,##0.00"
.Columns(6).NumberFormat = "#,##0.00"
.Cells(1, 1) = "Vendor Number"
.Cells(1, 2) = "Vendor Name"
.Cells(1, 3) = "Invoice ID"
.Cells(1, 4) = "Due Date"
.Cells(1, 5) = "Native Inv Amount"
.Cells(1, 6) = "USD Invoice Amount"
.Cells(1, 7) = "Mark to Pay"
End With
'return user to summary tab
summary.PivotTables("PivotTable1").PivotCache.Refresh
summary.Range("A1").Select
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
Для половины из нас, использующих макрос, все работает отлично. Для другой половины они получают ошибку Range - Method.