+ Reply to Thread
Results 1 to 5 of 5

Manipulating range from listbox

  1. #1
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    Manipulating range from listbox

    Hi,
    I'm not sure if it's possible but I'm trying.. it may be a bit tautological.
    I've got a range (say a1:g10) which is being displayed by a listbox (which contains 7 columns) placed in userform.
    Within this listbox I can easily "mark" with the mouse a specific row (say a2:g2), question: can I delete that marked row? in other words is it possible to "affect" the original "database" (a1:g10) from the listbox?
    Please * if you like the answer

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,943

    Re: Manipulating range from listbox

    Of course - just make sure that you specify the sheet in the rowsource string, like
    'Sheet1'!A1:G10
    and assign code like this to a commandbutton on your userform.

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    Re: Manipulating range from listbox

    Thanks Bernie. It works smoothly!. For better understanding: why to use negative STEP?
    Also, in this line - no need to specify which RANGE are we talking about?
    Range(Me.ListBox1.RowSource).Rows(i + 1).Delete

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,943

    Re: Manipulating range from listbox

    I used negative step because I was not sure if your listbox was mulit-select - deleting row 2 will change row 3 to row 2, and then the indexing is messed up. Easier to just go backwards...

    And we are specifying the range:
    Range(Me.ListBox1.RowSource).Rows(i + 1)

    Me.ListBox1.RowSource is a range address - with or without the sheetname - add these lines and you will see

    Msgbox Me.ListBox1.RowSource
    Msgbox Range(Me.ListBox1.RowSource).Address
    Msgbox Range(Me.ListBox1.RowSource).Rows(i + 1).Address

  5. #5
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    Re: Manipulating range from listbox

    Thanks alot for the clarifications.

+ 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. Creating a Range of a Listbox based on the Selection Made in Another ListBox
    By masood78 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-02-2014, 11:03 AM
  2. [SOLVED] Indexing proper range in listbox depending on selection in previous listbox
    By bloodmeat in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-02-2013, 02:31 PM
  3. Replies: 2
    Last Post: 05-04-2011, 08:09 PM
  4. Manipulating dynamic range via data validation list
    By ryantaylor in forum Excel General
    Replies: 0
    Last Post: 01-12-2011, 04:58 AM
  5. newbie: manipulating cols & rows in named range
    By DavidH in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-27-2005, 02:05 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