+ Reply to Thread
Results 1 to 17 of 17

Delete row source from selected line in ListBox

  1. #1
    Registered User
    Join Date
    08-10-2011
    Location
    Monaco
    MS-Off Ver
    Excel 2010
    Posts
    31

    Delete row source from selected line in ListBox

    OK, several problems here...

    In my UserForm when I click on "Find"...

    1. ListBox not filling in properly
    What should appear for the row source in question (in a row from left to right) is:
    Column A (TextBox1), then
    Column B (TextBox2), then
    Column H (TextBox3)
    Column I (TextBox4)
    Column J (TextBox5)
    Column K (ComboBox6)
    Column L (Combobox7)
    Column M (TextBox8)
    Column O (TextBox11)


    2. Selecting item in ListBox doesn't select row source
    When I click on an item in the listbox, I should not just fill in the relevant TextBoxes / ComboBoxes with the row source, it should go to the row source in the sheet, that way when I delete an item, it doesn't just delete the first line in the listbox (even when this is not the selected line).

    3. Deleting rows - deletes first item in listbox, not selected item
    Same problem as above, but not sure if I need to fix the code for "delete" or the code for "listbox click." Basically, when I click on "delete" button, I want to delete the row in the worksheet that corresponds to the selected line in the listbox. What is happening now is that when I click on "Find," the active cell defaults to the first item found and not the selected item in the listbox. Gosh. Hope I'm explaining correctly!!!!

    Help, please!!! Below are the codes.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Delete row source from selected line in ListBox

    1 What exactly is the problem?

    Is it that the listbox isn't populating correctly?

    That could be because the listbox ColumnCount is 1, try changing it to 9.

    2 There doesn't appear to be any code to delete from the worksheet?

    3 See above.
    Last edited by Norie; 02-12-2013 at 07:09 AM.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    08-10-2011
    Location
    Monaco
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Delete row source from selected line in ListBox

    1. Huh?? Could you rewrite that portion of the code?? (Yes, the issue is that the listbox is not populating correctly - it only shows the date [column A], but should be followed by the other columns as per my OP.)

    2. The code to delete is posted above and also in the attachment. Try opening the attachment and clicking on "ADD TRANSACTION", then "Find", then select something from the listbox, then click "Delete" and you will see what I mean. It deletes the row in the sheet based on the activecell (the cell selected by the "Find" macro), and not the row I want (the activecell should be the one relating to the item selected in the listbox).
    Last edited by PinkMafia14; 02-12-2013 at 07:58 AM.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Delete row source from selected line in ListBox

    1 Rewrite what code? All you need to do is change the ColumnCount of the listbox from 1 to 9 which can be done in design view.

    2 Oops, missed the delete code - - I was looking at the code in the workbook

    The selecting and deleting code have a similar problem.

    That is that you aren't working with the row of data on the worksheet that corresponds to the row selected in the listbox.

    What makes that hard is that you won't necessarily be dealing with contiguous rows of data so you can't use listindex.

    For example you have Cash in rows 402, 404 and 408.

    In the listbox those rows will have the listindices 0,1 and 2 respectively - so there's no direct relation between listindex and row number.

    What you'll need to do is store the row numbers, in a hidden column, in the listbox along with the rest of the data.

    Then when you want to delete the data you can refer to that column to find the row.

    Hope that makes some sort of sense.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Delete row source from selected line in ListBox

    Have a look at the attached.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    08-10-2011
    Location
    Monaco
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Delete row source from selected line in ListBox

    1. Ok - done, thanks

    2. In your example, I am not sure what you have used as a reference? The amount in column J (value in Euros)? What happens if I have two entries with that value??
    Last edited by PinkMafia14; 02-12-2013 at 11:39 AM.

  7. #7
    Registered User
    Join Date
    08-10-2011
    Location
    Monaco
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Delete row source from selected line in ListBox

    Ignore last question. I'm not sure how it works, but after testing it's coming out fine.

    Next problem: the formula in the TextBox5 ("Amount in Euros (formula)") works when you input manually, but goes all funny when it's populated by the listbox (seems to be a formatting thing with the commas/periods)...

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Delete row source from selected line in ListBox

    It looks fine to me, apart from no currency symbol.

    Mind you I don't see where it's being formatted.

  9. #9
    Registered User
    Join Date
    08-10-2011
    Location
    Monaco
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Delete row source from selected line in ListBox

    If I click on any item that has an FX rate, the formulas gives "stupid" responses, like "-87,666666" for EUR "-10.52 / 1.2" (should be -8.7666666 - note the decimal)


    ETA - it's not formatted... It just calculates TextBox3 / TextBox4 (amount / exchange rate).
    Last edited by PinkMafia14; 02-12-2013 at 12:30 PM.

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Delete row source from selected line in ListBox

    Sorry I can't even find the numbers you've quoted.

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Delete row source from selected line in ListBox

    Just remembered a slight problem - the sheet is password protected so I can't make certain changes in it.

    For example I was going to test the latest problem with some dummy values but Excel wasn't having it.

  12. #12
    Registered User
    Join Date
    08-10-2011
    Location
    Monaco
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Delete row source from selected line in ListBox

    Yes - sorry... I added lines to test the formula. See attached (click on first line - ITEM 4).

    ETA - to unprotect in column AA (grouped) click on the "lock" icon... This unprotects the sheet (temporarily whilst I test the file). Refresh formulas to re-protect.
    Attached Files Attached Files
    Last edited by PinkMafia14; 02-12-2013 at 12:40 PM.

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Delete row source from selected line in ListBox

    There's no button but I found the code to unprotect.

    Just tried the form again and values in textbox5 look fine and tally to what's in the listbox.

    They could do with rounding/formatting I suppose.

    PS ETA?

  14. #14
    Registered User
    Join Date
    08-10-2011
    Location
    Monaco
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Delete row source from selected line in ListBox

    That's so weird... When I click, it goes retarded... If there is nothing in the exchange rate, it comes out especially stupid...

    But as I said, there is no formatting in the code, just "TextBox5.Value = TextBox3.Value / TextBox4.Value"... Could it be to do with my local/country excel settings? Friggin French formatting with their ";" for commas and and "," for periods...


    "ETA" = Edited To Add
    Last edited by PinkMafia14; 02-12-2013 at 12:57 PM.

  15. #15
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Delete row source from selected line in ListBox

    This might not help but try changing the code for TextBox3 and Textbox4 to this.
    Please Login or Register  to view this content.
    By the way, why do you have 2 sets of code for finding matching rows?

    The first one actually just seems to be counting the no of rows that match.

    If that is all it's doing it can be replaced with Application.CountIf.
    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    08-10-2011
    Location
    Monaco
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Delete row source from selected line in ListBox

    I have done all of this by googling how to write VBA and amending codes to my needs... Occasionally, I get stuck and can't find the answers without asking the questions with my exact issues... Hence why the codes are not as efficient as they could/should be... It's people like you who help ignorant people like me when we can't rely on anyone around us to know what we're talking about!!! So THANK YOU!!! I've tweaked it a bit, and it all seems to work - I've learned a lot today!
    Last edited by PinkMafia14; 02-12-2013 at 01:18 PM.

  17. #17
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Delete row source from selected line in ListBox

    No problem.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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