Consulting

Results 1 to 2 of 2

Thread: Dynamically creating variables...possible?

  1. #1
    VBAX Newbie
    Joined
    Jul 2010
    Location
    Indianapolis, IN
    Posts
    4
    Location

    Dynamically creating variables...possible?

    All,

    I was wondering if there was a way to dynamically create variables based inconsistent range selections? For these purposes I just fixed the column positions, but you understand that this might just be field names of various tables (or whatever) This is a trimmed down version of what Im trying to do and, like I said, I have no idea if its possible...

    [vba]Sub dynamicVarCreation()

    Dim i As Integer
    Dim left_Selection_Col As Integer
    Dim right_Selection_Col As Integer

    left_Selection_Col = 1
    right_Selection_Col = 7

    i = left_Selection_Col

    For i = left_Selection_Col To right_Selection_Col - left_Selection_Col + 1

    dim "Var" & i as Variant

    Next i

    End Sub[/vba]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    No, you can't do that. That is what arrays are for.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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