Determining number of columns of 2 different ranges

  • Thread starter Thread starter filo666
  • Start date Start date
F

filo666

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
 
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
 
Dim ra As Range

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

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top