access a cell in a range

K

keyser_Soze

I have variables:

dim myrange as Range
dim myString as String

myrange specifies a specific column. How can I specify the cell in row
1 of myRange so I can set it's contents to myString?
 
Z

Zack Barresse

Hi there keyser soze,

(Fan of the movie, eh? ;) <g> )

Like so ..

myString = myRange(1).Value

HTH
 
K

keyser_Soze

yes, I liked the movie.

Shouldn't that be
myRange(1).value = myString

?

Thanks again
 
Z

Zack Barresse

Not if you want to set the contents of your variable to the cell value, as
you stated.
 
Z

Zack Barresse

I'm sorry, I thought I replied to this, not sure what happened..

If you're looking to set your variable value from this, then no, you don't
want to do it that way. It would be ...

myString = myRange(1, lngColumn).Value

Where lngColumn is a variable (either input by hand or used as an actual
variable) which specifies your desired column. If you are wanting to set
the desired cell as a range variable and not as a string varible, it would
look like this ...

Set myRange = Cells(1, lngColumn)

Same principal applies to the lngColumn. Substitute a column number if
you'd like, or use a variable.
 

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

Top