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

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Need help with Procedure to return selected column numbers

Another one -

Sub test2()
Dim nColFirst As Long, nColLast As Long
Dim sMsg As String
Dim ar As Range

Range("B2:B9,D2:E9,G2:I9").Select

For Each ar In Selection.Areas
With ar
nColFirst = .Column
nColLast = nColFirst + .Columns.Count - 1
If nColLast = nColFirst Then
sMsg = sMsg & nColFirst & " "
Else
sMsg = sMsg & nColFirst & ":" & nColLast & " "
End If
End With
Next

MsgBox sMsg
End Sub

Regards,
Peter T

"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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Need help with Procedure to return selected column numbers

One more...

Option Explicit
Sub testme()

Dim myStr As String
Dim myCell As Range
Dim myRng As Range

With ActiveSheet
Set myRng = Intersect(Selection.EntireColumn, .Rows(1))
End With

myStr = ""
For Each myCell In myRng.Cells
myStr = myStr & ", " & myCell.Column
Next myCell

myStr = Mid(myStr, 3)

MsgBox myStr
End Sub

Dan Thompson wrote:

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


--

Dave Peterson
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
Need help with Procedure to return selected column numbers JLGWhiz[_2_] Excel Programming 0 April 17th 09 07:07 PM
Need help with Procedure to return selected column numbers Tushar Mehta[_4_] Excel Programming 0 April 17th 09 06:56 PM
Need help with Procedure to return selected column numbers Patrick Molloy[_2_] Excel Programming 0 April 17th 09 06:46 PM
Function to return # of column with min value in selected rows mr_espresso Excel Worksheet Functions 9 June 24th 06 08:54 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 03:18 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"