PDA

View Full Version : How can you read with a VBA Excel Sub a vector from the worksheet?



akindofmagic
09-13-2010, 10:50 PM
Let's say I have a worksheet in Excel. The purpose of the Sub is to read various vectors through an InputBox, without the Sub asking the user the number of elements for that vector.
I assume:


Sub vect()
Dim aVector as Range
Set aVector = Application.InputBox = ("Vector range", type:=8)
' Display the vector trough Debug.Print
End Sub


Thank you.

mikerickson
09-14-2010, 07:53 AM
You'll need to remove one = sign and add some handling
Sub vect()
Dim aVector As Range

On Error Resume Next
Set aVector = Application.InputBox ("Vector range", type:=8)
On Error GoTo 0

if aVector Is Nothing Then
MsgBox "cancel pressed."
Else
MsgBox aVector.Address(,,,True) & " selected"
End If
End Sub