Skip to content

Commit 11d59b8

Browse files
committed
Add note on qualifying range objects
1 parent 3ae0f4f commit 11d59b8

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ This is an evolving document. Submit a pull request and start the conversation!
234234
'do stuff with each worksheet
235235
Next wks
236236
```
237+
237238
* Prefer `With...End With` blocks to reduce repetition.
238239

239240
```vb
@@ -245,3 +246,17 @@ This is an evolving document. Submit a pull request and start the conversation!
245246
Set rng = .Range(.Cells(1, 1), .Cells(lngLastRow, 1))
246247
End With
247248
```
249+
250+
* Qualify `Range` objects with a `Worksheet`.
251+
252+
```vb
253+
'Bad
254+
Set rng = Range(Cells(1, 1), Cells(lngIdx, 1))
255+
256+
'Good
257+
Set wks = ThisWorkbook.Worksheets("Data")
258+
With wks
259+
Set rng = .Range(.Cells(1, 1), .Cells(lngIdx, 1))
260+
End With
261+
```
262+

0 commit comments

Comments
 (0)