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

1. ## 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
-

2. ## 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. ## 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.

4. ## 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>

#### Posting Permissions

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