简体   繁体   中英

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

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

You can also call it with Selection object

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM