We have a user with an old 97-2003 Excel document with macros in, which they were using and running in 2013 without issue.
We have now upgraded to 2016 over the weekend, and when running the first macro in the workbook, cells that would normally show us a value, now show #REF!
Oddly, if we correct some of the references manually after the macro has run, then run the macro again, it does not have the same issue the second time around.
We are wondering if there are any changes in 2016 that might cause macros to behave in this way?
The first macro we are running is below:
Sub Update()
'
' Macro1 Macro
' Macro recorded 28/06/2007 by PETER WILSON
''
'
Sheets("DCodes2").Select
Range("C4").Select
Application.CutCopyMode = False
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("Summary").Select
Range("D23").Select
Sheets("Sales Inv").Select
Range("a2").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Range("K5").Select
Sheets("Invoices").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("Job Costs").Select
ActiveWindow.LargeScroll ToRight:=-1
Range("C2").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
ActiveWindow.SmallScroll ToRight:=6
Range("N2:T2").Select
Selection.AutoFill Destination:=Range("N2:T284")
Range("N2:T284").Select
Range("N3").Select
Range("J28").Select
Sheets("Job Costs").Select
ActiveWindow.SmallScroll ToRight:=-1
Range("N2:T2").Select
ActiveWindow.LargeScroll ToRight:=-2
ActiveWindow.SmallScroll ToRight:=9
Selection.AutoFilter Field:=1
Range("N2:T2").Select
Selection.Copy
Range("N3").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Paste
Sheets("Daybook").Select
Range("B2").Select
Application.CutCopyMode = False
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("Job Costs").Select
Range("N2:U2").Select
Sheets("Summary").Select
Range("I8").Select
'
End Sub
I am not clear on what the macro is supposed to be doing, so I am hesitant to go through and try to manually correct for the user in case I get something wrong, and I don't know enough about Visual Basic to determine what the above code is doing at each step.
Looks like some of the original code was recorded. This (below) appears to give the same functionality, removing extraneous and unnecessary code. (but I can't see the original sheets of course so treat this cautiously)
Sub EquivalentFunctIonality
Dim qt as QueryTable
Dim ws as Worksheet
For each ws in Worksheets
For Each qt in ws.querytables
qt.refresh BackgroundQuery:=False
Next qt
next ws
With Worksheets("Job Costs")
.Range("N2:T2").Copy .range(Range("N3"),.range("n3").End(xlDown))
End With
End Sub
See if this still gives errors.
At this time I have not been able to find any change to 2016 that could be related to this issue.
I have just made manual corrections to the invalid references generated by the first run of the Macro, and allowed it to re-run (apparently successfully every subsequent time).
I have asked the end user to continually monitor the data in the workbook to ensure it is accurate, and will tackle any future workbooks with the same kind of issue in a similar way.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.