What formula will give a result of column address which reflects the last nonempty column used in the worksheet?
eg. if there is
something in C1, H1, and M1, and
something in F3, and
something in AA6
Thanks
Regards, francis
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Return the last column address (Excel 2003)
You could use this custom VBA function:
Function LastColumn(oCell As Range)
LastColumn = oCell.Parent.Cells.Find(What:=”*”, SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
End Function
In a cell formula:
=LastColumn(A1)
or if you place the function in your Normal.dot:
=Personal.xls!LastColumn(A1)
You can also retrieve the last used column in another sheet, if desired:
=LastColumn(Sheet3!A1)
Hans,
I am trying to adapt this custom function to a project I am working on. I need to determine the last column used within columns X:AZ for each row of a spreadsheet and then return the value of row 1 for that column into a cell. It seems as if this function is looking at the entire worksheet even if I enter a range in the formula. Any suggestions? Would another formula work better?
I have attached a sample workbook. The column I am looking to populate is W.
Thanks!
Greg
The function that I posted indeed looks at the entire worksheet; this was by intent.
You should use a different formula: in W3, enter this formula:
=INDEX($X$1:$AZ$1,MATCH(9.99999999999999E+307,$X3:$AZ3))
If necessary, format the cell as a date, and fill down as far as needed. The formula will return #N/A if no payments have been made, which is not unreasonable. If you’d like to suppress the error value, you can use
=IF(ISNA(MATCH(9.99999999999999E+307,$X3:$AZ3)),””,INDEX($X$1:$AZ$1,MATCH(9.99999999999999E+307,$X3:$AZ3)))
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.
Notifications