Loop through worksheets - add sheet name to extraction

03856me

Active Member
Joined
Apr 4, 2008
Messages
297
Help with ws.Name = I am creating a summary page that will clear and refresh each time a new worksheet is added by the user. On the Summary page I want to pull the ws.Name into column A. This code is working except it is pulling the summary page worksheet name of "TOTALS". Here is a snippet of what I want the TOTALS page to look like as well as my existing code. Thank you for helping.

Capture.PNG


VBA Code:
Sub MakeSummaryTable()
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    
    Dim wb As Workbook:  Set wb = ThisWorkbook
    Dim ws As Worksheet
        Set ws = wb.Sheets("TOTALS")
    
    ClearData_TOTALS
    
   For Each ws In Worksheets
        If ws.Name <> "Master" And ws.Name <> "Summary" And ws.Name <> "Recap" And ws.Name <> "TEXT" Then
                Range("A100").End(xlUp).Offset(1, 0).Value = ActiveSheet.Name       'worksheet #
                Range("B100").End(xlUp).Offset(1, 0).Value = ws.Range("L39").Value       'Total Today - LBS/SY
        End If
    Next ws

Application.ScreenUpdating = True
    Application.DisplayAlerts = True

End Sub

'======================================================================================
Sub ClearData_TOTALS()
    Range("A4:C100").Select
        Selection.ClearContents
 
End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Looks like you just need to use ws.Name not Activesheet.Name.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,601
Messages
6,120,467
Members
448,965
Latest member
grijken

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