If Selection..

jstevens
GoldLounger
Posts: 2628
Joined: 26 Jan 2010, 16:31
Location: Southern California

If Selection..

Post by jstevens »

Is it possible to determine the first and last column of a "selection" of cells?

Example of what I'm trying to achieve.

Code: Select all

IF a range of cells is selected and the Columns are "C to F" then 
     process some code
ELSE
     do nothing
END IF   
Regards,
John

User avatar
HansV
Administrator
Posts: 78447
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: If Selection..

Post by HansV »

If the selection is a single contiguous rectangular area:

Code: Select all

    Dim FirstCol As Long
    Dim LastCol As Long
    FirstCol = Selection.Column
    LastCol = Selection.Column + Selection.Columns.Count - 1
FirstCol and LastCol are column numbers, so columns C to F would correspond with FirstCol = 3 and LastCol = 6.
Best wishes,
Hans

jstevens
GoldLounger
Posts: 2628
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: If Selection..

Post by jstevens »

Hans,

Thank you.
Regards,
John