Disclaimer: I'm heavily involved in the development of Rubberduck.
Consider this common mistake:
lastRow = Worksheets("Sheet12").Cells(1, Rows.Count).End(xlUp).Row
Rows
is unqualified, and therefore implicitly refers to the active sheet and therefore Rows.Count
isn't necessarily the row count on "Sheet12". The code might work, but it could also result in a subtle bug where lastRow
doesn't have the correct value because of this, depending on the content of the active sheet.
Or this one:
ActiveWorkbook.Worksheets("SummarySheet") _
.ListObjects("Table1").Sort.SortFields.Add _
Key:=Range("Table1[[#All],["Date]]"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortTextAsNumbers
See it? Because the Key
parameter isn't qualified, the call is going to fail at run-time with error 1004 - "Method 'Range' of object '_Global' failed". That's 169 Stack Overflow questions. "Error 1004" yields 1465 Stack Overflow questions.
Implicit references to the active worksheet are a very common cause of bugs.
Rubberduck's VBA code inspections are, like ReSharper's C# static code analysis, hints/suggestions. The tool is telling you that it's possible there's something here that could cause problems, or that makes the code less explicit than it could be.
Do you need to fully qualify every single Range
call? Of course not - Rubberduck is merely letting you know that in these instances, ActiveSheet
is implicitly being referenced, that's all there is to it.
You can always tell Rubberduck "look, I know what I'm doing", using the "Ignore once" quick-fix:

That "fix" inserts a special comment (internally, Rubberduck calls them "annotations") that instructs the inspection to ignore specific results, while leaving the inspection enabled:
With ActiveWorkbook
Set wsMacro = .Worksheets("Macro")
Set wsORatio = .Worksheets("ORatio" & TabNum)
With wsORatio
sMap = "oratio" & TabNum & "map"
'@Ignore ImplicitActiveSheetReference
For CurrentRow = 1 To Range(sMap).Rows.Count
'@Ignore ImplicitActiveSheetReference
Test = Range(sMap).Cells(CurrentRow, 1)
Set wsData = ActiveWorkbook.Worksheets(Test)
'@Ignore ImplicitActiveSheetReference
Start = Range(Range(sMap).Cells(CurrentRow, 2)).Row
Report = wsMacro.Range(sMap).Cells(CurrentRow, 3)
For Cat = 0 To 12
For iMth = 1 To 12
wsORatio.Cells(Report + Cat, 7 + iMth) = wsData.Cells(Start + Cat, 37 + iMth)
Next iMth
Next Cat
Next CurrentRow
End With
End With
These annotations have the advantage of telling the reader (future you, or whoever takes your code over) that there's something going on here.
Future versions will eventually support specifying @Ignore
annotations once at module-level, to ignore all results of a particular inspection in an entire module.
Note that the inspection is under the Maintainability and Readability Issues category. Range("DefinedName")
isn't half as explicit and fail-safe as:
ActiveWorkbook.Names("DefinedName").RefersToRange
Which gives you the same range, and reads like it's actually pulling a named range scoped at workbook level.