Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find last column with data

Thanx very much


Kind Regard

--
Message posted from http://www.ExcelForum.com

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
FInd common data in one column then add number in adjacent column JT Excel Worksheet Functions 3 December 18th 09 10:20 PM
FIND COLUMN DATA Dave Excel Discussion (Misc queries) 8 June 4th 09 07:16 PM
Find last column with data? Myles Excel Discussion (Misc queries) 3 March 27th 09 07:20 PM
compare data in column A with column B to find duplicates George Excel Discussion (Misc queries) 8 February 6th 09 03:53 PM
find rows for unique data in 1 column and different data in other. Dot Majewski Excel Discussion (Misc queries) 1 January 21st 05 12:23 AM


All times are GMT +1. The time now is 08:10 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"