LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Need help with Procedure to return selected column numbers

I don't believe you will have much luck with that. Here is an excerpt from
the VBA help file:

When applied to a Range object that's a multiple-area selection, this
property returns columns from only the first area of the range. For example,
if the Range object has two areas- A1:B2 and C3:D4- Selection.Columns.Count
returns 2, not 4. To use this property on a range that may contain a
multiple-area selection, test Areas.Count to determine whether the range
contains more than one area. If it does, loop over each area in the range.

You would have to use Columns.Count for the selected range, then add that
result -1 to the starting column number to get the column range. i.e. If
you select D4:J4, then Selection.Column.Count would yield a count of 7. You
know you are in coluimn D or Columns(4), so if you add 7 - 1 or 6, it gives
you 10, therefor, your range is columns 4:10.





"Dan Thompson" wrote in message
...
I am having trouble with this macro

Sub ReturnColumnNumbers()
Dim ColNum As Integer
ColNum = Selection.Column
MsgBox ("The Selected Column Numbers are" & Chr(13) & ColNum)
End Sub

The problem is it works when I select just one column but if I select more
than one column it does not return the other column numbers ?

Any thoughts ?

Dan Thompson



 
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
Need help with Procedure to return selected column numbers Patrick Molloy[_2_] Excel Programming 0 April 17th 09 06:46 PM
how to sort a column of Randomly selected numbers? Khoshravan Excel Worksheet Functions 8 July 14th 07 08:16 PM
Function to return # of column with min value in selected rows mr_espresso Excel Worksheet Functions 9 June 24th 06 08:54 PM
Increment numbers in column A by 1 when selected mikeburg[_83_] Excel Programming 4 June 14th 06 10:18 PM
Add selected numbers in a column that are a different color Sam Excel Discussion (Misc queries) 6 March 4th 05 11:46 PM


All times are GMT +1. The time now is 11:44 PM.

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

About Us

"It's about Microsoft Excel"