Cell names

M

Murray

I have a little problem that maybe someone can explain to me. If I try to
access a cell as a variant all i do is get an error message. I have tried as
follows

Dim i As Integer
Dim testcell As Variant

i = 1

For i = 1 To 10

testcell = "C" & Str(i)
Range("testcell").Text = Str(i)
Next i

I thought this should count the cells C1 to C10 and write the number 1 to 10
in eache of these cells.
Does anyone know what else I have done wrong

Thanx
M
 
A

Art Farrell

Hi Murray,

I don't know exactly what you're trying to accomplish, but the following
will work:

Dim i As Integer
Dim testcell As Variant

i = 1
For i = 1 To 10
testcell = "C" & i
ActiveSheet.Range(testcell) = i
Next i

Two items. When you define testcell as:

testcell = "C" & Str(i)

Str puts a leading space before the number so you are getting

testcell = "C 1" with the space which doesn't work for a cell address.
Also, when you use testcell as the Range you don'y want the quotes

around the word.

CHORDially,
Art Farrell
 

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