+ Reply to Thread
Results 1 to 16 of 16

Count columns

  1. #1
    Registered User
    Join Date
    06-06-2007
    Location
    NYC, NY
    Posts
    66

    Count columns

    How can I count the number of used columns in a specific row? The below code doesn't work.
    Please Login or Register  to view this content.
    Last edited by EnergyEngineer; 09-28-2007 at 03:26 PM.

  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
    This will found last used column for activecell

    Please Login or Register  to view this content.
    assumes it's not xl 2007

    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
    06-06-2007
    Location
    NYC, NY
    Posts
    66

    Thumbs up I used...

    I used this and it worked. Thanks!

    Please Login or Register  to view this content.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Quote Originally Posted by EnergyEngineer
    I used this and it worked. Thanks!

    Please Login or Register  to view this content.
    Does it work with the speech marks around 71?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    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
    Glad it helped.

    Just a tip. You can use the VBA recorder to give you

    Please Login or Register  to view this content.
    Where selection is a cell in the last column then mod as required

    VBA Noob

  6. #6
    Registered User
    Join Date
    06-06-2007
    Location
    NYC, NY
    Posts
    66

    Cool Noticed that

    Yah I noticed that and I just fixed it. It worked but I took it out since it was extra.

    Thanks,
    ~RUTH~

  7. #7
    Registered User
    Join Date
    06-06-2007
    Location
    NYC, NY
    Posts
    66

    Cool Needed # for a loop

    Thanks but I needed the count for a loop.

    ~RUTH~

  8. #8
    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
    I meant use the recorder to give you the direction then tweak. So change selection with your ref and last column

    hope that makes sense

    VBA Noob

  9. #9
    Registered User
    Join Date
    06-06-2007
    Location
    NYC, NY
    Posts
    66

    Thumbs up Understood

    Yah I got it. Thanks! The macro recorder is pretty nifty. Sometimes I like to figure it out the hard way.

    ~RUTH~

  10. #10
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Count columns

    Quote Originally Posted by EnergyEngineer
    I used this and it worked. Thanks!

    Please Login or Register  to view this content.
    Does it work if there's a value in Col_256?

    Try something like this:
    Please Login or Register  to view this content.
    Does that help?
    Last edited by Ron Coderre; 09-28-2007 at 04:23 PM.
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  11. #11
    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
    Hard way being the forum

    VBA Noob

  12. #12
    Registered User
    Join Date
    06-06-2007
    Location
    NYC, NY
    Posts
    66

    256 columns?

    No I don't think I will ever have something in column 256. Thanks for the debug thought.

    ~RUTH~

  13. #13
    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
    If you select cell say A256 and you press Ctrl + left arrow it will take you to either A1 if no cells filled in or any cell that has a value.

    When you record this action you get

    Please Login or Register  to view this content.
    Then change selection as you did to

    Please Login or Register  to view this content.
    Your row and last column of spreadsheet

    by changing

    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    you return the column number

    HTH

    VBA Noob

  14. #14
    Registered User
    Join Date
    06-06-2007
    Location
    NYC, NY
    Posts
    66

    Smile Understood x2

    Yah yah I understood what you were saying. Thanks for the detailed explanation.

    ~RUTH~

  15. #15
    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
    Good to hear.

    However I thought I should explain as your comment below seem to me that you didn't understand

    Quote Originally Posted by EnergyEngineer
    No I don't think I will ever have something in column 256. Thanks for the debug thought.

    ~RUTH~
    VBA Noob

  16. #16
    Registered User
    Join Date
    06-06-2007
    Location
    NYC, NY
    Posts
    66

    Question ?

    That was in response to Ron and his thought if there was something in cell 256.

    ~RUTH~

+ 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