• Access and Excel – Ref Last Column in Excel (A2k SR1)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Access and Excel – Ref Last Column in Excel (A2k SR1)

    • This topic has 3 replies, 2 voices, and was last updated 20 years ago.
    Author
    Topic
    #419502

    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

    Viewing 0 reply threads
    Author
    Replies
    • #947401

      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)

      • #947402

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

      • #947407

        BTW – The link to the Daily Dose of Excel will be very helpful. Thanks. thumbup

    Viewing 0 reply threads
    Reply To: Access and Excel – Ref Last Column in Excel (A2k SR1)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: