Sam
Sam

Reputation: 65

Extract a worksheet name from the range selected

I have to input the result in the selected cell through InputBox function:

Set OutputStrt = Application.InputBox("Select a cell, where the output should be dropped.", "Output start cell", Type:=8)

When I ran the code in the different worksheet and want the result in the different worksheet, it drops the result in the worksheet where I initially ran the code.

How do I get the Worksheet name, which I selected through the Application.InputBox ?

For example, when I selected in the Inputbox: Definitions!$F$38 how do I get the name 'Definitions'?

Upvotes: 3

Views: 13954

Answers (2)

GeoStoneMarten
GeoStoneMarten

Reputation: 583

You can also call it with Selection object

Dim ws As Workseet
Set ws = Selection.Worksheet
Debug.Print "Sheetname: " & ws.Name

Upvotes: 0

Fadi
Fadi

Reputation: 3322

Try This:

Sub test()
    Dim Ws As Worksheet
    Dim OutputStrt As Range
    Set OutputStrt = Application.InputBox("Select a cell, where the output should be dropped.", "Output start cell", Type:=8)
    Set Ws = OutputStrt.Worksheet
    MsgBox Ws.Name
End Sub

Upvotes: 3

Related Questions