Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

selecting non adjacent cells

  Asked By: Hasan    Date: Oct 18    Category: MS Office    Views: 552
  

I need to select several nonadjacent cells, without knowing what row
they're in. The row is being represented by an integer that is being
increased by a for loop. The Macro Recorder gave me something
like "Range ("A!, C3, G2").select." I wanted something that would let
me use the integer value. I tried it like "Range((1,1), (2,2),
(3,3)).select." No go. So I tried "Range("A" & x).select" (x being my
integer value.). Still no cigar. Any ideas?


Share: 

 

2 Answers Found

 
Answer #1    Answered By: Adelino Fischer     Answered On: Oct 18

Use the Union command, like this:

Union(Cells(1, 1), Cells(2, 2), Cells(3, 3)).Select

Hope this helps,

 
Answer #2    Answered By: Joseph Evans     Answered On: Oct 18

Well, 'Range("A" & x).select' should select  the cell in column A in the row
represented by the number in x. Sounds as though x might not have a valid
value in it.

As far as I know, putting commas directly into the parameter list of a Range
call can only be used to describe the top left and bottom right of a
rectangle.

However, you can put commas inside a single string provided to Range as a
parameter - e.g. 'Range ("A1, C3, G2").select'. (Note that your example has
A! not A1. Is that a direct copy out of your code?). And, if you can do
that, you can construct a string that looks like that - just remember that
the commas are part of the string, not parameter separators.

I'm not sure how you can provide Range with R1C1 type information (in fact,
I believe you can't), so you need to use column letters.

I'm not sure why you need to select non-adjacent cells  from within code.
Have a look at your requirement and see if there is a different way of doing
it.

 
Didn't find what you were looking for? Find more on selecting non adjacent cells Or get search suggestion and latest updates.




Tagged: