Macro to list sheet names and last cell value of each sheet

guybrown

Board Regular
Joined
Jul 2, 2008
Messages
100
Hi

Is there a macro that creates a list of all the worksheet names and the value of the last cell from each worksheet?

eg.
RO3 $35,480.00
GE1 $106,425.00
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Perhaps a tweak of the following including Ctrl End, copy, paste value beside sheet name?

Sub SheetNames()
Columns(1).Insert
For i = 1 To Sheets.Count
Cells(i, 1) = Sheets(i).Name
Next i
End Sub
 
Upvote 0
You should clarify what "last cell" means to you. Example, if a sheet has 4 columns, and column D's last row is 8, and column B's last row is 12, do you want the value from B12 or D8.
 
Upvote 0
Let's say you have only two pieces of data, one in D6 and the other in A7... which is the "last cell" to you?
 
Upvote 0
Thanks for responding - appreciated

In answer to your question: Both - I have a tables of different sizes and always want the last cell
eg.
F13 from A1:F13
F17 from A1:F17

The cell that is selected when I hold down Ctrl key and press the End key
The table on each worksheet has a blue line around it and no grid outside of the blue line. Maybe it's a 'print area' or something. When I click Ctrl End it always goes to the cell i want copied...

Hope that helps.
 
Upvote 0
Code:
Sub SheetsLastItem()
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.EnableEvents = False
Dim strSummary$, iSheet%, LR&, LC&
strSummary = "zzzSummary"
On Error Resume Next
Sheets(strSummary).Delete
Err.Clear
Sheets.Add(After:=Sheets(Sheets.Count)).Name = strSummary
Range("A1:B1").Value = Array("Sheet name", "Last Item")
For iSheet = 1 To Sheets.Count - 1
With Sheets(iSheet)
Cells(iSheet + 1, 1).Value = .Name
If WorksheetFunction.CountA(.Cells) = 0 Then
LR = 1: LC = 1
Else
LR = .Cells.Find(What:="*", After:=.Range("A1"), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
LC = .Cells.Find(What:="*", After:=.Range("A1"), SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
Cells(iSheet + 1, 2).Value = .Cells(LR, LC).Value
End If
End With
Next iSheet
Columns(1).AutoFit: Columns(2).AutoFit
.EnableEvents = True
.DisplayAlerts = True
.ScreenUpdating = True
End With
End Sub
 
Upvote 0
This macro outputs your requested list to the ActiveSheet (the ActiveSheet is not reported on)...

Code:
Sub ListLastCells()
  Dim WS As Worksheet, OutputRow As Long
  OutputRow = 1
  On Error Resume Next
  For Each WS In Worksheets
    If WS.Name <> ActiveSheet.Name Then
      ActiveSheet.Cells(OutputRow, "A").Value = WS.Name
      ActiveSheet.Cells(OutputRow, "B").Value = WS.Cells(WS.Cells.Find(What:="*", SearchOrder:=xlRows, _
                                                SearchDirection:=xlPrevious, LookIn:=xlValues).Row, _
                                                WS.Cells.Find(What:="*", SearchOrder:=xlByColumns, _
                                                SearchDirection:=xlPrevious, LookIn:=xlValues).Column).Address(0, 0)
      If Err.Number Then
        ActiveSheet.Cells(OutputRow, "B").Value = "<<EMPTY Sheet>>"
        Err.Clear
      End If
      OutputRow = OutputRow + 1
    End If
  Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,719
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top