![]() |
Find last column with data
Hi Experts
I am trying to find the last column with data in my sheet. I tried thi code, but it is giving me errors. Do you have any ideas what I'm doin wrong? lastcol = Cells(Columns.Count, "2").End(xlLeft).Column Kind Regard -- Message posted from http://www.ExcelForum.com |
Find last column with data
Hi Poppy,
lastcol = Cells(Columns.Count, "2").End(xlLeft).Column If you use a numeric column reference, drop the quotes. The Cells syntaax should be: Cells(row, column) To find the last populated cell in row 2, try amending your code to: Set lastcol = Cells(2, Columns.Count).End(xlToLeft) To return the number of the find the last populated column in row 2, try: Cells(2, Columns.Count).End(xlToLeft).Column To find the last populated column on the worksheet, try the following function: Function LastCol(sh As Worksheet) On Error Resume Next LastCol = sh.Cells.Find(What:="*", _ After:=sh.Range("A1"), _ Lookat:=xlPart, _ LookIn:=xlFormulas, _ SearchOrder:=xlByColumns, _ SearchDirection:=xlPrevious, _ MatchCase:=False).Column On Error GoTo 0 End Function --- Regards, Norman "poppy " wrote in message ... Hi Experts I am trying to find the last column with data in my sheet. I tried this code, but it is giving me errors. Do you have any ideas what I'm doing wrong? lastcol = Cells(Columns.Count, "2").End(xlLeft).Column Kind Regards --- Message posted from http://www.ExcelForum.com/ |
Find last column with data
|
All times are GMT +1. The time now is 01:29 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com