Search code examples
excelvbaselectrangeinputbox

With help of Application.InputBox() method let user to select multiple cells


I have a code in VBA, where with help of inputBox method user is able to select a cell, a range. But I need to have an inputBox where user is able to select multiple cell ranges, ( not with help of Selection method!!) then to split each cell value.

code is below

Set Group = Application.InputBox(prompt:="Select a cell to be expanded", Left:=100, Type:=8)

Dim str_group As String

Debug.Print Split(str_group, ":")(0)

type:=8 give ability to select only a cell, Mcrsteven if user selects multiple cells, it only reads first cell range(address) I need to see after : and to be able to read it.


Solution

  • Try this article by Microsoft official website.

    https://learn.microsoft.com/en-us/office/vba/api/excel.application.inputbox
    

    In my case the below code worked just fine.

    Sub test()
        Dim myRange As Variant
        Set myRange = Application.InputBox(prompt:="Select a cell to be expanded", Type:=8)
        Debug.Print myRange.Address
    End Sub
    

    Debug output was $A$4:$C$11 as I selected those cells. Hope this is helpful ...