Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2008

Tip: Looking for answers? Try searching our database.

Determining number of columns of 2 different ranges

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
filo666 - 16 Jan 2008 09:16 GMT
I'm selecting two separate areas of my worksheet using Ctrl-Click(drag);
a1:a4 and c1:c4

I would like to know how to get the column number 1 for colum "A" and 3 for
colum "C".
pd,  I'm not always using the same areas (it could be d1:d56 and g1:g7; and
in this case I want 4 and 7 respectivly).

TIA
papou - 16 Jan 2008 10:08 GMT
Hi
May be this will do:
Dim colOne As Integer, colTwo As Integer
colOne = Cells(1, Mid(Left(Selection.Address, 2), 2, 1)).Column
colTwo = Cells(1, Left(Right(Selection.Address, 3), 1)).Column

MsgBox "First column = " & colOne & vbLf _
& "Second column = " & colTwo

HTH
Cordially
Pascal

> I'm selecting two separate areas of my worksheet using Ctrl-Click(drag);
> a1:a4 and c1:c4
[quoted text clipped - 7 lines]
>
> TIA
Peter T - 16 Jan 2008 10:09 GMT
Dim ra As Range

For Each ra In Selection.Areas
Debug.Print ra.Columns(1).Column
Next

Regards,
Peter T

> I'm selecting two separate areas of my worksheet using Ctrl-Click(drag);
> a1:a4 and c1:c4
[quoted text clipped - 5 lines]
>
> TIA
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.