Consulting

Results 1 to 2 of 2

Thread: How can you read with a VBA Excel Sub a vector from the worksheet?

  1. #1

    Cool How can you read with a VBA Excel Sub a vector from the worksheet?

    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:

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

    Thank you.

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    You'll need to remove one = sign and add some handling
    [VBA]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[/VBA]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •