+ Reply to Thread
Results 1 to 7 of 7

The Correct Syntax For Using Variables With Square Bracket Arrays

  1. #1
    Forum Contributor
    Join Date
    10-29-2019
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    156

    The Correct Syntax For Using Variables With Square Bracket Arrays

    Hi

    I need the correct syntax for using variables with square brackets.

    [a11:ab11] = var

    Works fine but when i add a variable it gives errors ie. [cx1 & ":" & cx2] = var

    Please dont give an answer using range & .value, it has to be square brackets, as im trying to figure out how to use it.

    Thanks & much appreciated

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: The Correct Syntax For Using Variables With Square Bracket Arrays

    Nevermind this is tantamount to a duplicate post.
    Last edited by xladept; 05-26-2020 at 02:11 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: The Correct Syntax For Using Variables With Square Bracket Arrays

    To my knowledge you cannot use square brackets to reference ranges while using a variable.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  4. #4
    Forum Contributor
    Join Date
    10-29-2019
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    156

    Re: The Correct Syntax For Using Variables With Square Bracket Arrays

    xladept

    cx1 = "a16"
    cx2 = "ai16"

  5. #5
    Forum Contributor
    Join Date
    10-29-2019
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    156

    Re: The Correct Syntax For Using Variables With Square Bracket Arrays

    Dim cx1 As String
    Dim cx2 As String

  6. #6
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,477

    Re: The Correct Syntax For Using Variables With Square Bracket Arrays

    Square bracket notation cannot use anything within it from the VBA world... it can only use Excel worksheet functions, references, etc. However, you can use Defined Names in the square brackets which can be set by VBA code. Not sure how efficient that would be, but it would work. For example, I am thinking something like this...
    Please Login or Register  to view this content.

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: The Correct Syntax For Using Variables With Square Bracket Arrays

    Quote Originally Posted by Genus Max View Post

    [a11:ab11] = var

    Works fine but when i add a variable it gives errors ie. [cx1 & ":" & cx2] = var
    Shortcut notation of Evaluate method doesn't accept variable, so
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA - Escape characters for square bracket
    By Cheesecube in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-09-2020, 11:29 AM
  2. [SOLVED] Square of the differences in two corresponding ranges of arrays and division
    By Vccjlc in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-20-2019, 05:16 AM
  3. Regression formula with more than 16 variables; need help with r-square, standard errors
    By snapcracklepop in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-17-2018, 11:26 AM
  4. VBA:SEARCH problem with square bracket []
    By Pongwipat in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-28-2015, 06:00 AM
  5. [SOLVED] Run-time error 1004 The formula is not complete. Make sure an ending square bracket ]
    By triaji in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-30-2014, 12:13 AM
  6. for/next Correct Syntax for Ranges with variables
    By beat in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-19-2013, 11:14 AM
  7. Replies: 0
    Last Post: 06-04-2013, 10:01 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1