Inputbox and Union

medwatt

New Member
Joined
Apr 1, 2014
Messages
5
Hello,
How do I set a range such that when the user sees the input box he can select no contiguous cells. How can these cells be united into a simple range.

I tried this but no luck :

Code:
Set rng = Application.Union(Application.InputBox("Please select paramters:", Type:=8))

Your help is appreciated
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
You don't need the Union:

Code:
    Set rng = Application.InputBox("Select some cells.", Type:=8)
    MsgBox rng.Address
 
Upvote 0
If the user enters a comma between selecting ranges, the range returned by the InputBox will be discontinuous.
Code:
Dim uiRange As Range

On Error Resume Next
Set uiRange = Application.InputBox("Select a range, press comma to select discontinous range", Type:=8)
On Error GoTo 0

If uiRange Is Nothing Then
    Rem cancel pressed
Else
    MsgBox "You selected " & uiRange.Address
End If
 
Upvote 0
How many different selections will you have? If two then maybe...

Code:
Sub Foo()
Set Rng1 = Application.InputBox("Please select parameter1", Type:=8)
Set Rng2 = Application.InputBox("Please select parameter2", Type:=8)
Set Rng = Application.Union(Rng1, Rng2)
End Sub
 
Upvote 0
Sorry, I should have added that the user needs to hold down the Ctrl key, the usual way for making multiple selections. The commas will be entered automatically.
 
Upvote 0
Thanks for the suggestions. My code is already written to access elements in the range (rng(i)). How should I modify it :

Code:
 For j = 3 To rng.Rows.Count
        If Application.Match(rng(j), wsHO.Rows(1), 0) Then
        Call blockArea(row, col, rng(j), dates)
            row = row + siteNo + 2
 End If
 
Upvote 0
You have to use a For Each loop:
Code:
Set rng = Application.InputBox("Please select paramters:", Type:=8)
For Each rngRow In rng.Rows
    Debug.Print rngRow.Address

 Next rngRow

The Cells and Range properties, when applied to a range object, are not restricted to cells within that parent range.
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,930
Members
449,094
Latest member
teemeren

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