1

I want to store the value of cell [136,7] in sheet Schools in a string

Dim Num As String

Num = Schools.Cells(136,7).Value

This code won't run. I am suspecting the error occurs because I cannot refer to my sheet directly use its name. But I do not know how to remedy this.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
koch
  • 107
  • 7

1 Answers1

1

Note that there are 2 different naming systems:

  1. The VBA code name of a worksheet (which can be changed in the Project Explorer in VBE)

    Num = Schools.Cells(136,7).Value
    
  2. The tab name of the worksheet (which can be changed by any user)

    Num = Worksheets("Schools").Cells(136,7).Value
    

Note that Schools and Worksheets("Schools") can be 2 completely different worksheets. These 2 naming systems are completely independend.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
  • It returns Application-defined or object-defined error when I use both – koch May 22 '19 at 14:20
  • @koch You should only use one of them. Try `ThisWorkbook.Worksheets("Schools")` then. Is the worksheet `Schools` in the same workbook as the code? – Pᴇʜ May 22 '19 at 14:23