+ Reply to Thread
Results 1 to 3 of 3

Range.columns.count property returns wrong count after union operation

  1. #1
    Registered User
    Join Date
    10-13-2008
    Location
    India
    Posts
    2

    Range.columns.count property returns wrong count after union operation

    With mybook.Worksheets(1)
    Set rngHeader = .Range(.Cells(1, 1), .Cells(10, 1))
    Set rngDayhead = .Range(.Cells(1, 3), .Cells(10, 3))
    End With

    Set rngSource = Union(rngHeader, rngDayhead)
    MsgBox rngSource.Columns.Count


    The above code pops a msg box with count 1 but actually it should return 2.

    Also if the line,
    Set rngDayhead = .Range(.Cells(1, 3), .Cells(10, 3))
    is replaced with
    Set rngDayhead = .Range(.Cells(1, 2), .Cells(10, 2))
    then the count comes correctly that is 2.

    What i don't understand is why the count is not 2 when a column in between is skipped?

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,431
    It's to do with non contiguous ranges.
    To handle them you need to use the Areas collection.

    Please Login or Register  to view this content.
    Please use code tags in future
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    10-13-2008
    Location
    India
    Posts
    2
    Thanks a lot Andy, it works

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Q on Column Count Operation
    By Digital in forum Excel General
    Replies: 4
    Last Post: 09-29-2008, 08:46 PM
  2. Totals from worksheets on a totals sheet
    By tongy66086 in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 05-17-2008, 09:50 PM
  3. Buttons to add lines
    By Glio in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-26-2007, 11:02 PM
  4. COUNT function returns zero
    By tkh in forum Excel General
    Replies: 2
    Last Post: 10-10-2006, 01:23 AM

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