MS Office Excel 2003 assigning cell values to variables

M

mike

Hello,

( MS Office Excel 2003 )

I'm getting a runtime 1004 error with for any/each of the following
statements.
I don't want to employ the standard Range("A1") object since the the
A1 is literal string,
and I need more progamatic control hence the Cells method.

The "wrap" variables are non-zero, and temp is not not declared so
that Excel VB
can determine the type as needed.

I've seen on-line doc with stated examples where these should work.

temp = Sheets("Sheet1").Cells(wrap_b, wrap_a).Value2
temp = Cells(wrap_b, wrap_a).Value2
temp = Sheets("Sheet1").Range(Cells(wrap_b, wrap_a), Cells(wrap_b,
wrap_a)).Value2


PS I've never understood the usefulness of the "string" parameter of
the Range() object ...

Thanks, Mike
 
J

JE McGimpsey

Hmm...

What are the values and types of wrap_a/wrap_b? VBA will round to the
nearest integer, so if wrap_a = 0.49, then you'll get the error you
report, since the value will be coerced to 0.

Of course, using a value > then number of rows or columns will also
cause the error.
PS I've never understood the usefulness of the "string" parameter of
the Range() object ...

For one thing, it's easier to read in many cases, especially if one is
used to using A1-style references in XL formulae. For another,

Range("B3:J10")

is arguably easier to write and understand than

Range(Cells(3, 1), Cells(10, 10))

or

Cells(3, 2).Resize(8, 9)
 

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