Finding Last Column in a given Row

  • Thread starter Thread starter Lance Hoffmeyer
  • Start date Start date
L

Lance Hoffmeyer

Hello,

How do I find the last nonempty column in a given row (say row 2)?

Lance
 
Hi, this function will give you the last non-empty cell in the last
column, just change the variable myRow to the row value as you need.

Function LastCell(Optional ws As Worksheet) As Range
Dim myRow&, myCol&, Rng As Range
If ws Is Nothing Then Set ws = ActiveSheet
Set Rng = ws.Cells
Set LastCell = Rng(1)
myRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
myCol = ActiveSheet.Cells(myRow, Columns.Count) _
..End(xlToLeft).Column
On Error Resume Next
Set LastCell = Intersect(Rows(myRow), Columns(myCol))
End Function

HTH--Lonnie M.
 
oops, this will give you the last non-empty cell in the last ROW.
 
Consider:
lastCell = Activesheet.Cells(2,Columns.Count).End(xltoLeft)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top