![]() |
Using "Cells" to write "Range("A:A,H:H").Select"
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 |
Using "Cells" to write "Range("A:A,H:H").Select"
Hi Trip,
Perhaps Union(Columns(1), Columns(8)) is what you are looking for. --- Regards, Norman "Trip Ives" wrote in message m... 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 |
Using "Cells" to write "Range("A:A,H:H").Select"
Try this:
Union(Cells(1, 1).EntireColumn, Cells(1, 8).EntireColumn).Select Using 8 as your second column. -- Message posted from http://www.ExcelForum.com |
Using "Cells" to write "Range("A:A,H:H").Select"
|
All times are GMT +1. The time now is 06:34 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com