ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Select filled region only in non-adjacent columns (https://www.excelbanter.com/excel-discussion-misc-queries/154864-select-filled-region-only-non-adjacent-columns.html)

hmm

Select filled region only in non-adjacent columns
 
I have just selected the non-hidden cells in several non-adjacent columns.
Now I want to select these columns only from row 1 to the maximum occupied
row. How do I do it?

joel

Select filled region only in non-adjacent columns
 
This code has been tested and works. I highlight multiple cells by holding
the Ctrl keys while selecting the cells. Had data in 5 different columns
which were non-adjacent.


Sub selectrows()

first = True
For Each cell In Selection
mycolumn = cell.Column
If first = True Then
Lastrow = Cells(Rows.Count, cell.Column).End(xlUp).Row
Set selectedRange = Range(Cells(1, cell.Column), _
Cells(Lastrow, cell.Column))
first = False
Else
Lastrow = Cells(Rows.Count, cell.Column).End(xlUp).Row
Set selectedRange = Union(selectedRange, _
Range(Cells(1, cell.Column), Cells(Lastrow, cell.Column)))
End If

Next cell

selectedRange.Select

End Sub

"hmm" wrote:

I have just selected the non-hidden cells in several non-adjacent columns.
Now I want to select these columns only from row 1 to the maximum occupied
row. How do I do it?



All times are GMT +1. The time now is 02:45 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com