Results 1 to 4 of 4
  1. #1
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Access and Excel - Ref Last Column in Excel (A2k SR1)

    Quick Question -

    In access, I can activate an excel application and determine the number of columns being used in the excel sheet using the formula:
    xlsht.range("IV2).END(xlToLeft).Column. (Thanks Hans)
    This works and returns an integer, i.e., 25 for the number of columns.

    However, in excel, this correlates to Column Y. Is there an easy way to convert the integer column number returned to the excel string representing the column number? (Anyone have a handy dandy function out there)

    I can also go to the last active cell and get its address returned as say $Y$43 but am looking for an easier solution as I will need to go to the last active cell, check to see if its value is zero, and if so, delete the column. Then loop through each prior columns last active cell until there are no longer any zeroes.

    ----
    To make this clearer
    - Open an excel worksheet
    - dim lac as variant 'Last Active Cell
    - Go to last active cell and set lac = value
    - if lac = zero then
    -- do while lac = zero
    --- delete column
    --- go to last active cell in prior column
    --- lac = value of current active cell
    - -loop
    end if
    -
    Regards,

    Gary
    (It's been a while!)

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

    Re: Access and Excel - Ref Last Column in Excel (A2k SR1)

    This is not really an Access question, of course.

    To return the column letter(s) corresponding to a column number, you can use

    Left(xlSht.Cells(1, ColNumber).Address(False, False), 1 - (ColNumber > 26))

    (source: Daily Dose of Excel - Column Numbers To Letters)

  3. #3
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Access and Excel - Ref Last Column in Excel (A2k SR1)

    Thanks Hans. I will have to start posting in excel. I am struggling here as I am not used to the excel objects.
    Regards,

    Gary
    (It's been a while!)

  4. #4
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Access and Excel - Ref Last Column in Excel (A2k SR1)

    BTW - The link to the Daily Dose of Excel will be very helpful. Thanks. <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>
    Regards,

    Gary
    (It's been a while!)

Posting Permissions

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