0

I only have a single workbook with one sheet open with only a number in cell(2,3).

when the code reaches this line:

Debug.Print Range(ActiveSheet.Cells(2, 3)).Value

or this line:

Range(ActiveSheet.Cells(2, 3)).Select

I get

Method of "range' of object'_gobal" failed

Since this line is essentially copied from "How to select cells/ranges by using Visual Basic procedures in Excel" in Microsoft Docs, I am perplexed as to why it doesn't work.

Sub testCode()
 Debug.Print ActiveSheet.Range(ActiveSheet.Cells(5, 3)).Value
 ActiveSheet.Range(ActiveSheet.Cells(5, 3)).Select
 End Sub
Scott Craner
  • 148,073
  • 10
  • 49
  • 81
Jaaks
  • 11
  • 1
  • 2
    Range wants two cells to create a range, just use `ActiveSheet.Cells(5, 3).Value` and `ActiveSheet.Cells(5, 3).Select` – Scott Craner May 21 '20 at 20:12
  • BTW: Microsoft docs aren't always the greatest... see for example [How to avoid using `Select`](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba). – BigBen May 21 '20 at 20:17
  • 1
    @NareshBhople yes it can take a string as a single cell. For example `Range("A1")` but when using actual range object it must be two, a start and a finish. As to your example the `Address` returns a string. But I would not recommend doing that as it is the long slow way around. See https://stackoverflow.com/questions/36073943/range-vs-cells-run-times – Scott Craner May 21 '20 at 20:50
  • @ScottCraner I got your point. You are referring cells as range object (Start and end) in your comment. Yes, I agree with you .. Thanks for response – Naresh May 21 '20 at 20:50
  • Thanks Scott. Using two cells (and only two, three also causes an error) solves the problem. – Jaaks May 22 '20 at 10:32

0 Answers0