3

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'?

Community
  • 1
  • 1
Sam
  • 65
  • 1
  • 1
  • 8

2 Answers2

3

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
Fadi
  • 3,302
  • 3
  • 18
  • 41
0

You can also call it with Selection object

Dim ws As Workseet
Set ws = Selection.Worksheet
Debug.Print "Sheetname: " & ws.Name
GeoStoneMarten
  • 533
  • 1
  • 7
  • 19