I’m familiar with Word objectmodel and VBA, but not at all with Excel. Using VBA, how can I get the coordinates of the last cell (row/column) that contains a value (is not empty)?
A client receives worksheets that contain a varying number of rows and sometimes 1 or 2 extra columns and she wants to put the Sum() of the last column two rows below the last cell with a value in that column.
![]() |
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 |
-
Last cell containing value (Win98 / Excel97)
Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Last cell containing value (Win98 / Excel97)
- This topic has 10 replies, 4 voices, and was last updated 20 years, 9 months ago.
AuthorTopicWSJanB
AskWoody LoungerSeptember 1, 2004 at 8:26 am #409303Viewing 3 reply threadsAuthorReplies-
WSJohnBF
AskWoody LoungerSeptember 1, 2004 at 2:36 pm #871394 -
H. Legare Coleman
AskWoody PlusSeptember 1, 2004 at 5:10 pm #871507John: That method can return unexpected results on at least some versions of Excel (XL2K which I use for example). If rows and/or columns have been deleted from the worksheet, and the workbook has not been saved, then your method can return a cell that is much below and/or to the right of the actual last used cell. The VBA function below should be more reliable:
Public Function FindLastCell(strWorksheet As String) As Range Dim oUsed As Range Dim I As Long, lLastRow As Long, lLastCol As Long, lLast As Long Set oUsed = Worksheets(strWorksheet).UsedRange lLastCol = 0 For I = 0 To oUsed.Rows.Count - 1 lLast = oUsed.Offset(I, oUsed.Columns.Count + 1).End(xlToLeft).Column If lLast > lLastCol Then lLastCol = lLast End If Next I lLastRow = 0 For I = 0 To oUsed.Rows.Count - 1 lLast = oUsed.Offset(oUsed.Rows.Count + 1, I).End(xlUp).Column If lLast > lLastRow Then lLastRow = lLast End If Next I Set FindLastCell = Range("A1").Offset(lLastRow - 1, lLastCol - 1) End Function
-
WSJohnBF
AskWoody LoungerSeptember 1, 2004 at 9:09 pm #871616Function lastusedcell() As String
Dim intCol As Integer
Dim lngRow As Long
For intCol = ActiveSheet.UsedRange.Columns.Count To 1 Step -1
If Application.WorksheetFunction.CountBlank(Columns(intCol)) < ActiveSheet.Rows.Count Then Exit For
Next intCol
For lngRow = ActiveSheet.UsedRange.Rows.Count To 1 Step -1
If Application.WorksheetFunction.CountBlank(Rows(lngRow)) < ActiveSheet.Columns.Count Then Exit For
Next lngRow
lastusedcell = ActiveSheet.Cells(lngRow, intCol).Address
End Function -
WSJohnBF
AskWoody LoungerSeptember 1, 2004 at 9:09 pm #871617Function lastusedcell() As String
Dim intCol As Integer
Dim lngRow As Long
For intCol = ActiveSheet.UsedRange.Columns.Count To 1 Step -1
If Application.WorksheetFunction.CountBlank(Columns(intCol)) < ActiveSheet.Rows.Count Then Exit For
Next intCol
For lngRow = ActiveSheet.UsedRange.Rows.Count To 1 Step -1
If Application.WorksheetFunction.CountBlank(Rows(lngRow)) < ActiveSheet.Columns.Count Then Exit For
Next lngRow
lastusedcell = ActiveSheet.Cells(lngRow, intCol).Address
End Function
-
-
-
H. Legare Coleman
AskWoody PlusSeptember 1, 2004 at 5:10 pm #871508John: That method can return unexpected results on at least some versions of Excel (XL2K which I use for example). If rows and/or columns have been deleted from the worksheet, and the workbook has not been saved, then your method can return a cell that is much below and/or to the right of the actual last used cell. The VBA function below should be more reliable:
Public Function FindLastCell(strWorksheet As String) As Range Dim oUsed As Range Dim I As Long, lLastRow As Long, lLastCol As Long, lLast As Long Set oUsed = Worksheets(strWorksheet).UsedRange lLastCol = 0 For I = 0 To oUsed.Rows.Count - 1 lLast = oUsed.Offset(I, oUsed.Columns.Count + 1).End(xlToLeft).Column If lLast > lLastCol Then lLastCol = lLast End If Next I lLastRow = 0 For I = 0 To oUsed.Rows.Count - 1 lLast = oUsed.Offset(oUsed.Rows.Count + 1, I).End(xlUp).Column If lLast > lLastRow Then lLastRow = lLast End If Next I Set FindLastCell = Range("A1").Offset(lLastRow - 1, lLastCol - 1) End Function
WSJohnBF
AskWoody LoungerSeptember 1, 2004 at 2:36 pm #871395WSJim Cone
AskWoody LoungerSeptember 1, 2004 at 9:20 pm #871624There is no need to run a loop…
‘=============================
‘Function BottomRightCorner
‘Jim Cone – San Francisco, CA
‘=============================
Function BottomRightCorner(ByRef objSheet As Worksheet) As Range
On Error GoTo NoCorner
Dim BottomRow As Long
Dim LastColumn As LongIf objSheet.FilterMode Then objSheet.ShowAllData
BottomRow = objSheet.Cells.Find(what:=”*”, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
LastColumn = objSheet.Cells.Find(what:=”*”, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
Set BottomRightCorner = objSheet.Cells(BottomRow, LastColumn)Exit Function
NoCorner:
beep
Set BottomRightCorner = objSheet.Cells(1, 1)
End FunctionWSJim Cone
AskWoody LoungerSeptember 1, 2004 at 9:20 pm #871625There is no need to run a loop…
‘=============================
‘Function BottomRightCorner
‘Jim Cone – San Francisco, CA
‘=============================
Function BottomRightCorner(ByRef objSheet As Worksheet) As Range
On Error GoTo NoCorner
Dim BottomRow As Long
Dim LastColumn As LongIf objSheet.FilterMode Then objSheet.ShowAllData
BottomRow = objSheet.Cells.Find(what:=”*”, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
LastColumn = objSheet.Cells.Find(what:=”*”, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
Set BottomRightCorner = objSheet.Cells(BottomRow, LastColumn)Exit Function
NoCorner:
beep
Set BottomRightCorner = objSheet.Cells(1, 1)
End FunctionViewing 3 reply threads -

Plus Membership
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.
Get Plus!
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.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
AMD : Out of Bounds (OOB) read vulnerability in TPM 2.0 CVE-2025-2884
by
Alex5723
59 minutes ago -
Totally remove or disable BitLocker
by
CWBillow
1 hour, 39 minutes ago -
Windows 10 gets 6 years of ESU?
by
n0ads
4 seconds ago -
Apple, Google stores still offer China-based VPNs, report says
by
Nibbled To Death By Ducks
11 hours, 45 minutes ago -
Search Forums only bring up my posts?
by
Deo
11 hours, 59 minutes ago -
Windows Spotlight broken on Enterprise and Pro for Workstations?
by
steeviebops
23 hours, 27 minutes ago -
Denmark wants to dump Microsoft for Linux + LibreOffice
by
Alex5723
16 hours, 4 minutes ago -
How to get Microsoft Defender to honor Group Policy Setting
by
Ralph
1 day ago -
Apple : Paragon’s iOS Mercenary Spyware Finds Journalists Target
by
Alex5723
1 day, 10 hours ago -
Music : The Rose Room – It’s Been A Long, Long Time album
by
Alex5723
1 day, 11 hours ago -
Disengage Bitlocker
by
CWBillow
1 day, 1 hour ago -
Mac Mini M2 Service Program for No Power Issue
by
Alex5723
1 day, 13 hours ago -
New Win 11 Pro Geekom Setup questions
by
Deo
11 hours, 54 minutes ago -
Windows 11 Insider Preview build 26200.5651 released to DEV
by
joep517
1 day, 20 hours ago -
Windows 11 Insider Preview build 26120.4441 (24H2) released to BETA
by
joep517
1 day, 20 hours ago -
iOS 26,, MacOS 26 : Create your own AI chatbot
by
Alex5723
2 days ago -
New PC transfer program recommendations?
by
DaveBoston
5 hours, 25 minutes ago -
Windows 11 Insider Preview Build 22631.5545 (23H2) released to Release Preview
by
joep517
2 days, 4 hours ago -
Windows 10 Build 19045.6029 (22H2) to Release Preview Channel
by
joep517
2 days, 4 hours ago -
Best tools for upgrading a Windows 10 to an 11
by
Susan Bradley
1 day, 16 hours ago -
The end of Windows 10 is approaching, consider Linux and LibreOffice
by
Alex5723
20 hours, 58 minutes ago -
Extended Windows Built-in Disk Cleanup Utility
by
bbearren
1 day, 5 hours ago -
Win 11 24H2 June 2025 Update breaks WIFI
by
dportenlanger
2 days, 23 hours ago -
Update from WinPro 10 v. 1511 on T460p?
by
CatoRenasci
1 day, 21 hours ago -
System Restore and Updates Paused
by
veteran
3 days, 2 hours ago -
Windows 10/11 clock app
by
Kathy Stevens
2 days, 13 hours ago -
Turn off right-click draw
by
Charles Billow
3 days, 5 hours ago -
Introducing ChromeOS M137 to The Stable Channel
by
Alex5723
3 days, 8 hours ago -
Brian Wilson (The Beach Boys) R.I.P
by
Alex5723
15 hours, 30 minutes ago -
Master patch listing for June 10, 2025
by
Susan Bradley
3 days, 10 hours ago
Recent blog posts
Key Links
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.