+ Reply to Thread
Results 1 to 6 of 6

Column Number for currentregion

Hybrid View

  1. #1
    Registered User
    Join Date
    04-24-2004
    Posts
    10

    Column Number for currentregion

    Hello

    I have a current region sitting anywhere in the sheet.

    What code returns the column number of the current region for the activecell/selection?

    I am after the column number of the region, not the column number of the sheet.

    Thanks for any help offered.

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Hi,

    To get the first column of the selection, use

    
    Dim ColNum As Integer 
    ColNum = Selection.Cells(1,1).Column

    To get the number of columns selected, use

     
    Dim ColCount As Integer 
    ColCount = Selection.Columns.Count
    Hope it helps

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    04-24-2004
    Posts
    10
    Thanks for the quick reply Noob.

    Not sure if that is what I am looking for.

    Say I have a currentregion E6:H28. The activecell/selection is G15.

    I want to return the columnnumber of the currentregion (3) for G15.

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Think this works


     
    Sub Macro4()
        Dim ColNum As Integer
        ColNum = Selection.Cells(1, 1).Column
        
        Selection.End(xlToLeft).Select
        MsgBox Abs(ActiveCell.Column - ColNum)
    End Sub
    VBA Noob

  5. #5
    Registered User
    Join Date
    04-24-2004
    Posts
    10
    Noob

    Right. I had already come up with something similar but I thought there must be a property and syntax which would give it to me in a single line.

    Thanks for your help.

  6. #6
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    No Problem

    VBA Noob

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1