must be too simple

  • Thread starter Thread starter Marie Lavoie
  • Start date Start date
M

Marie Lavoie

Hi.
I've programmed A BIT in VB before, but never with Excel. And i'm really
having trouble with a stupid thing. To indicate a cell to excel...
I only want him to read the value of a cell!
A sort of:

If Main!A5= "CLS" Then
....
....
End If

How to I write this "Main!A5" ??

Thank you.

Marie
 
Marie

If Sheets("Main").Range("A5") = "CLS" Then

Regards

Trevor
 
Hi, Marie. Are you trying to read the value of the cell with Visual Basic,
or with an Excel VBA macro?

Ed
 
Marie,
'Sheets("Main").Range("A5")', properly speaking, is a Range object (the
cell), not a String (the text the cell displays). Using
'Sheets("Main").Range("A5") = "CLS"' relies on VBAs "default value" of the
Range object to return the String value of the cell. Allowing VBA to
determine whether to return the cell or the text the cell displays can be
unreliable under some not-very-rare circumstances. I recommend that you be
unambiguous and use 'Sheets("Main").Range("A5").Text' which always returns
the text the cell displays and never returns the cell.

Bob Kilmer
 

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