0

My intent is to select every other cell in a row. My code (I'm sure there's got to be a better way to accomplish this but one step at a time I guess):

Range("C" & row & ":C" & row + 1 & ", E" & row & ":E" & row + 1 & ", G" & row & ":G" & row + 1 & ", I" & row & ":I" & row + 1 & ", K" & row & ":K" & row + 1 & ", M" & row & ":M" & row + 1 & ", O" & row & ":O" & row + 1 & ", Q" & row & ":Q" & row + 1 & ", S" & row & ":S" & row + 1 & ", U" & row & ":U" & row + 1 & ", W" & row & ":W" & row + 1 & ", Y" & row & ":Y" & row + 1 & ", AA" & row & ":AA" & row + 1 & ", AC" & row & ":AC" & row + 1 & ", AE" & row & ":AE" & row + 1 & ", AG" & row & ":AG" & row + 1 & ", AI" & row & ":AI" & row + 1 & ", AK" & row & ":AK" & row + 1 & ", AM" & row & ":AM" & row + 1 & ", AO" & row & ":AO" & row + 1 & ", AQ" & row & ":AQ" & row + 1 & ", AS" & row & ":AS" & row + 1 & ", AU" & row & ":AU" & row + 1 & ", AW" & row & ":AW" & row + 1 & ", AY" & row & ":AY" & row + 1 & ", BA" & row & ":BA" & row + 1).Select

I am incrementing by 2 to highlight every other row as well. It returns an error (Method 'range' of object' _Global' failed) when row is anything over 10. I have been unable to find any answers through Google. Doesn't seem to be a common issue. I'm truly mystified as to why it only works for single digit rows. Any help is appreciated.

2
  • 3
    IIR there's a 255 character limit for a text Range specification.
    – Comintern
    Commented Dec 19, 2016 at 20:35
  • Or take the whole string and paste it in the immediate window like this ?string to see what is it producing
    – Vityata
    Commented Dec 19, 2016 at 20:37

1 Answer 1

3

This may be much easier to code | read | debug.

Dim ws as Worksheet
Set ws = Worksheets("mySheet") 'change as needed

Dim x as Integer
For x = 3 to 53 Step 2 'loop from C to BA skipping 1 column in between

   Dim rngEveryOther as Range
   If rngEveryOther is Nothing
       Set rngEveryOther = ws.Range(ws.Cells(i,x),ws.Cells(i+1,x))
   Else
       Set rngEveryOther = Union(rngEveryOther, ws.Range(ws.Cells(i,x),ws.Cells(i+1,x)))
   End If

Next

rngEveryOther.Select

The Union statement will join cells into an existing range (if that is not obvious from the code).

1
  • A little adjustment and it works like a charm! Thank you so much! Commented Dec 19, 2016 at 20:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.