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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
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,213,494
Messages
6,113,981
Members
448,538
Latest member
alex78

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