Name of accessed worksheet

gtd526

Well-known Member
Joined
Jul 30, 2013
Messages
657
Office Version
  1. 2019
Platform
  1. Windows
Hello,
I'm looking for the worksheet name of the sheet being accessed to get the formulas (results = A1).
Here is the code I'm using:
VBA Code:
Sub ListFormulas()

    Dim Rng As Range
    Dim WorkRng As Range
    Dim xSheet As Worksheet
    Dim xRow As Integer
    
'        xTitleId = "Range Of Cells for Formula"
        
        Set WorkRng = Range("A1:Z100")
'        Set WorkRng = Application.Selection
'        Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
        Set WorkRng = WorkRng.SpecialCells(xlFormulas, 23)
        If WorkRng Is Nothing Then Exit Sub
        
        Application.ScreenUpdating = False
            Set xSheet = Application.ActiveWorkbook.Worksheets.Add

[B]'            xSheet.Range("A1") = ActiveSheet.Name 'not working
'            xSheet.Range("A1") = WorkRng.ActiveSheet.Name 'not working[/B]

            
            xSheet.Range("A2:C2") = Array("Address", "Formula", "Value")
            xSheet.Range("A2:C2").Font.Bold = True
            xRow = 3
            For Each Rng In WorkRng
                xSheet.Cells(xRow, 1) = Rng.Address(RowAbsolute:=False, ColumnAbsolute:=False)
                xSheet.Cells(xRow, 2) = " " & Rng.Formula
                xSheet.Cells(xRow, 3) = Rng.Value
                xRow = xRow + 1
        Next
        xSheet.Columns("A:C").AutoFit
        Application.ScreenUpdating = True
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
How about
VBA Code:
xSheet.Range("A1") = WorkRng.Parent.Name
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,810
Messages
6,121,690
Members
449,048
Latest member
81jamesacct

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