Using "Cells" to write "Range("A:A,H:H").Select"

  • Thread starter Thread starter Trip Ives
  • Start date Start date
T

Trip Ives

Hello all,

I'm trying to select two non-contigious columns but do not know the
position of the second column because it changes depending on the
user's input. Thus, I need to calculate the position of the second
column. Thus, using "Cells" makes this operation much easier.

I know that the following do not work as they select all columns
between - I only want the two end columns:
Range(Cells(1, 1), Cells(1, 8)).EntireColumn.Select
Range(Cells(1, 1), Cells(1, 8).EntireColumn).Select
Range(Cells(1, 1).EntireColumn, Cells(1, 8).EntireColumn).Select

The only other option I can think of is to calculate the column number
and then run it through a big case-statement to derive the column name
and then piece together the standard range syntax using variables.
But that seems rediculous.

Any thoughts?

Thanks!

Trip
 
Hi Trip,

Perhaps

Union(Columns(1), Columns(8))

is what you are looking for.
 
Try this:

Union(Cells(1, 1).EntireColumn, Cells(1, 8).EntireColumn).Select

Using 8 as your second column.
 

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

Back
Top