Using InputBox to Capture Selected Range in Excel Programming.

N

Neeraja

Hi,

Could you please help me with selecting different set of
ranges at one point of time with an input box in MS Excel
programming? It's like the user will select a range then
using the Ctrl key select another range at the same time.


Sub InputRange()

Dim varRange As Variant

On Error Resume Next

Set varRange = _
Application.InputBox("Select a range of cells:",
Type:=8)

If IsObject(varRange) = False Then Exit Sub

MsgBox varRange.Rows.Count

End Sub

The above code selects a single range.

Could someone Let me know asap.

Thanks
Neeraja.
 
D

Dave Peterson

Maybe this'll help:

Option Explicit
Sub InputRange()

Dim varRange As Range
Dim myArea As Range

On Error Resume Next
Set varRange = _
Application.InputBox("Select a range of cells:", Type:=8)
On Error GoTo 0

If varRange Is Nothing Then Exit Sub

varRange.select

'or
For Each myArea In varRange.Areas
MsgBox myArea.Rows.Count & "-" & myArea.Address
Next myArea

'or
MsgBox Intersect(varRange.EntireRow, varRange.Parent.Columns(1)).Cells.Count

End Sub
 
N

Neeraja

This worked! Thanks a Million!!

-----Original Message-----
Maybe this'll help:

Option Explicit
Sub InputRange()

Dim varRange As Range
Dim myArea As Range

On Error Resume Next
Set varRange = _
Application.InputBox("Select a range of cells:", Type:=8)
On Error GoTo 0

If varRange Is Nothing Then Exit Sub

varRange.select

'or
For Each myArea In varRange.Areas
MsgBox myArea.Rows.Count & "-" & myArea.Address
Next myArea

'or
MsgBox Intersect(varRange.EntireRow, varRange.Parent.Columns(1)).Cells.Count

End Sub


--

Dave Peterson
(e-mail address removed)
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top