Reference to cell - VBA

  • Thread starter Thread starter Darryl Kirtland
  • Start date Start date
D

Darryl Kirtland

Hi

I'm trying to write a user defined function which references a cell in sheet
1 in my spreadsheet. Cell A10 currently has the value of 20 - how do I
reference this cell in my VBA program.

Thanks

Darryl
 
Try this:


Code:
--------------------
Dim n as integer
n = Sheets(1).Cells(10,1).value
--------------------


where the 10 is row number as 1 is column number (hence A10).
A more efficient a safer way of referencing cells is to give them
names. So for example in your worksheet you defined cell A10's name to
be -number- then you can use the following code.


Code:
--------------------
Dim n as integer
n = Sheets(1).Range("number").value
--------------------


This way if you were to shift cell A10 to some other location on the
sheet you will not have to change the code.

Hope this helps!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top