+ Reply to Thread
Results 1 to 6 of 6

excel vba - Ubound with Listbox referencing

  1. #1
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    excel vba - Ubound with Listbox referencing

    I was hoping that someone could help me out with this. I have a bit of code where I'm having to move the original data columns from Columns A-D to columns AV-AY. I thought it would be fairly straight forward with changing the reference columns and indexes, but I seem to be running into some errors. I'm pretty sure I've got the indexing and column values referenced correctly, but if anyone could help me with the For line, I would be highly appreciative.
    Here is the original code that works:
    Please Login or Register  to view this content.
    Here is my altered code that doesn't work:
    Please Login or Register  to view this content.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,532

    Re: excel vba - Ubound with Listbox referencing

    Go back to

    UBound(v, 1)

    There was no reason to change this to 48 and I'm not sure what you had in mind. The second argument means "the upper bound of the first dimension of v". The first dimension of v is simply the number of rows in v.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: excel vba - Ubound with Listbox referencing

    Just change v to the new range and leave the rest untouched.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: excel vba - Ubound with Listbox referencing

    You only had to change the one line in your original code. The other numbers you changed are not column indices from the worksheet.

    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 10-29-2017 at 03:07 PM. Reason: typo
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  5. #5
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: excel vba - Ubound with Listbox referencing

    Thanks for the clarification, Jeff. Much appreciated. Works now. I was overthinking it. Forgot that v is already defining the range.

  6. #6
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: excel vba - Ubound with Listbox referencing

    Thanks AlphaFrog. Yeah I was overthinking it.

+ 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. [SOLVED] referencing listbox entry in new userform
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-27-2017, 07:59 AM
  2. ReDim v(UBound(b) - (UBound(b) < 0), 1)
    By maroon1 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-24-2016, 08:35 AM
  3. Listbox needs referencing to correct Worksheet
    By burger160 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-20-2014, 07:42 AM
  4. [SOLVED] Referencing ListBox value in UserForm issues
    By strud in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-09-2014, 06:46 AM
  5. ReDim Y(1 To UBound(X, 1) * UBound(X, 2), 1 To 8)
    By sohaila in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-15-2014, 05:48 PM
  6. VLookup fromula referencing a listbox and executed by a command button
    By raymondjdawson in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-26-2012, 09:55 PM
  7. Listbox Sheet Referencing
    By l8sk8r in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-11-2009, 01:51 AM

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