Parsing values into ranges

  • Thread starter Thread starter Andreww
  • Start date Start date
A

Andreww

Hi - I am trying to increment a value in a range, as below. I get a message
saying "Expected list seperator or )"


dim ii as int

For ii = 7 To 19
Range("M" & str(ii):"S"+str(ii)).Select

do stuff

next


Have tried changing & for + and taking out str...


Any thoughts?

Cheers

Andrew
 
The first problem you have is that the colon needs to go inside the
string:

Range("M" & ii & ":S" & ii).Select

The second problem is the Str() returns a value with a leading space
(if positive) so M & Str(ii) returns "M 7" instead of "M7"

As shown above, you can simply use the integer variable.

OTOH, you could also do less string manipulation:

For ii = 7 to 9
Range("M" & ii).Resize(1, 7).Select

Next ii

or

For ii = 7 to 9
Cells(ii, 13).Resize(1, 7).Select
Next ii

etc.
 
Back
Top