I'm trying to write a VBA macro for a group that has one workbook where they daily create new worksheets, but they also have Sheet 1, Sheet 2, Sheet 3 at the end of their long list of sheets. I need to create a external cell reference in a new column in a different workbook where this information is being summarized, so I need to know how to get the last non-empty sheet so I can grab this data and place it appropriately in the summary.
+5
A:
This function works through the sheets from right to left until it finds a non-blank sheet, and returns its name
Function GetLastNonEmptySheetName() As String
Dim i As Long
For i = Worksheets.Count To 1 Step -1
If Sheets(i).UsedRange.Cells.Count > 1 Then
GetLastNonEmptySheetName = Sheets(i).Name
Exit Function
End If
Next i
End Function
dbb
2008-11-11 14:12:15
Thanks! I've been diving into excel VBA and learning fast I think but its different from the languages I know.
Tony Peterson
2008-11-11 14:21:47