Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
hmm hmm is offline
external usenet poster
 
Posts: 175
Default 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?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default 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?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Select an item from dropdown list but return value from adjacent c StevanT Excel Discussion (Misc queries) 4 March 17th 07 12:39 PM
Set cell to record date when adjacent cell is filled AND NOT RESET The new guy Excel Worksheet Functions 3 February 26th 07 06:11 PM
My pivot table does not accept select non-adjacent columns? UT Excel Discussion (Misc queries) 0 September 27th 06 11:42 PM
Select a range of non-adjacent cells in Excel? hodgsonk Excel Worksheet Functions 12 July 1st 06 04:34 AM
I have a formula that copies itself when adjacent cells are filled in. How? Paul987 Excel Discussion (Misc queries) 2 March 22nd 06 05:22 PM


All times are GMT +1. The time now is 09:05 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"