-1

I'm using the following code to try and select the cell at the intersection of MyRow and MyCol. The current values are MyRow: 6 and MyCol: 4 which should select D6.

I can't get the correct syntax for the last line which is where it fails:

Sub SelectCS()
    Dim MyRow As Integer
    Dim MyCol As Integer
    MyRow = Sheet1.Range("a4").Value
    MyCol = Sheet1.Range("a5").Value
    Range((MyRow), (MyCol)).Select
End Sub
Comintern
  • 21,855
  • 5
  • 33
  • 80
JeffM
  • 1
  • 1

2 Answers2

3

Range(Integer, Integer) isn't a valid call. You should use Cells instead:

Cells(MyRow, MyCol).Select

Note that you should probably declare MyRow and MyCol as Long if you're using them to represent rows and columns. You should also avoid using the global Range object (I'd assume that this is for Sheet1, so it should be Sheet1.Cells or Sheet1.Range), and unless this is for UI you should probably not be using Select either.

Community
  • 1
  • 1
Comintern
  • 21,855
  • 5
  • 33
  • 80
0
Public Sub SelectCS()
    Dim MyRow As Integer
    Dim MyCol As Integer
    MyRow = Range("A1").Value
    MyCol = Range("B1").Value
   Cells(MyRow, MyCol).Select
End Sub
zatbusch
  • 324
  • 2
  • 10