Results 1 to 4 of 4
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Dynamic Range Column Count (03)

    Is it possible to determine the total number of columns in a dynamic range through VBA?

    Example:
    Range("A1:C1") should return 3 columns

    Range("C5:F5") should return 4 columns

    Thanks,
    John

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Dynamic Range Column Count (03)

    Have you tried the obvious .Columns.Count ? For example Range("A1:C1").Columns.Count

  3. #3
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Dynamic Range Column Count (03)

    John

    This is not really your answer as Hans has provided it but this little macro does the job:

    Sub CountColumns()

    Worksheets("Sheet1").Activate
    areaCount = Selection.Areas.Count
    If areaCount <= 1 Then
    MsgBox "The selection contains " & _
    Selection.Columns.Count & " columns."
    Else
    For i = 1 To areaCount
    MsgBox "Area " & i & " of the selection contains " & _
    Selection.Areas(i).Columns.Count & " columns."



    Next i
    End If
    Jerry

  4. #4
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Dynamic Range Column Count (03)

    Hans,

    Thank you. I was not aware of the column.count.

    John

Posting Permissions

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