ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Need help with Procedure to return selected column numbers (https://www.excelbanter.com/excel-programming/427116-re-need-help-procedure-return-selected-column-numbers.html)

Tushar Mehta[_4_]

Need help with Procedure to return selected column numbers
 
If you check the documentation for the Column property, you will find it
applies only to the first element. You should loop through all the columns
in the selection.

Sub showColNbrs()
Dim aCol As Range, sMsg As String
For Each aCol In Selection.Columns
sMsg = sMsg & aCol.Column & ", "
Next aCol
MsgBox Left(sMsg, Len(sMsg) - 2)
End Sub
--
Tushar Mehta
http://www.tushar-mehta.com
Custom business solutions leveraging a multi-disciplinary approach
In Excel 2007 double-click to format may not work; right click and select
from the menu


"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



All times are GMT +1. The time now is 12:41 AM.

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