+ Reply to Thread
Results 1 to 5 of 5

Listbox creating problems deleting a record

  1. #1
    Forum Contributor
    Join Date
    07-19-2019
    Location
    Illinois, USA
    MS-Off Ver
    365
    Posts
    164

    Listbox creating problems deleting a record

    I've figured out the majority of what I'm after, here, but I can't wrap my head around how to specify the listbox selection for the copying section of my code





    What I want it to do is when you select a record from the listbox and hit "delete", it will first copy the record being deleted to a tab called "Deleted Log"

    I'm able to delete the correct log from the listbox, BUT, the "copy" and "paste" method is copying the row that's selected on the worksheet, not the row that's selected in the listbox...




    Attached is sheet, and code is below
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by PrimePorkchop; 09-21-2020 at 10:55 PM.

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

    Re: Listbox creating problems deleting a record

    acr = Me.assetLogDisplay.ListIndex + 2
    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.

  3. #3
    Forum Contributor
    Join Date
    07-19-2019
    Location
    Illinois, USA
    MS-Off Ver
    365
    Posts
    164

    Re: Listbox creating problems deleting a record

    Quote Originally Posted by AlphaFrog View Post
    acr = Me.assetLogDisplay.ListIndex + 2
    amazing how easily it comes to you.

    Thank you so much for the help, works flawlessly

    I'm just curious, for purposes of my learning... why +2? I know the code works, but I don't get what the +2 is telling excel to do

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

    Re: Listbox creating problems deleting a record

    The first row in the listbox is index 0

    The first data row on the sheet is 2

    Add 2 to the index of the selected item on the listbox will be the sheet row number of the selected item.

    You are doing the exact same thing here...
    Sheet1.ListObjects(1).ListRows(.ListIndex + 1).Delete
    ...except the .ListRows(1) starts at row 2 on the sheet. So you only have to add 1 to the .ListIndex to get the .ListRow number (not the actual row number).
    Last edited by AlphaFrog; 09-22-2020 at 12:53 AM.

  5. #5
    Forum Contributor
    Join Date
    07-19-2019
    Location
    Illinois, USA
    MS-Off Ver
    365
    Posts
    164

    Re: Listbox creating problems deleting a record

    Interesting... I still don't know why they're treated differently (listbox vs data row) - but - I have a lot of data now from you that I can begin exploring it

    I appreciate the follow-up, thank you!

+ 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] Problems creating charts using listbox selection
    By cinstanl in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-15-2016, 01:45 PM
  2. 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
  3. Having problems populating a multicolumn listbox changing Listbox column with a loop.
    By Aristizabal95 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-11-2013, 12:41 PM
  4. Replies: 1
    Last Post: 01-17-2012, 10:47 AM
  5. Problems in creating a listbox()
    By jray9242 in forum Excel General
    Replies: 2
    Last Post: 10-14-2011, 02:19 PM
  6. VBA: Listbox with 1 record
    By hendre in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-24-2009, 04:12 PM
  7. VBA: Creating listbox similar to the one in Pivot table (Listbox+Checkbox)
    By modjoe23 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-18-2005, 09:35 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