Results 1 to 21 of 21

Thread: Combo Boxes

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    11

    Combo Boxes

    I have a combo box in a userform linked to a rowsource. I also have a macro in the userform. What I want to happen is when the combo box has selected an item and the button is clicked I want the item selected to be deleted and the cell to the right of it too.

    For example..

    Rowsource
    A1
    A2
    A3
    A4
    A5

    In the combo box I picked cell A3. When I press the button I want the content of cell A3 and B3 deleted.
    Last edited by TheRealDave; Mar 15th, 2006 at 05:23 PM.

  2. #2
    Addicted Member sweet_dreams's Avatar
    Join Date
    Apr 2005
    Location
    Poland, Lodz
    Posts
    189

    Re: Combo Boxes

    Hi, TheRealDave

    Paste this code to your Button Click event:

    VB Code:
    1. Dim address As Range
    2. Set address = Range(ComboBox1.Value)
    3. address.Select
    4. address.ClearContents
    5. address.Offset(0, 1).Select
    6. Selection.ClearContents

    hope this help

    regards,
    sweet_dreams
    using VB 2010 .NET Framework 4.0; MS Office 2010; SQL Server 2008 R2 Express Edition | Remember to mark resolved threads and rate useful posts.

  3. #3
    Addicted Member sweet_dreams's Avatar
    Join Date
    Apr 2005
    Location
    Poland, Lodz
    Posts
    189

    Re: Combo Boxes

    i optimalized my previous code now looks better

    VB Code:
    1. Range(ComboBox1.Value).Select
    2. Range(ActiveCell, ActiveCell.Offset(0, 1)).ClearContents

    regards,
    sweet_dreams
    using VB 2010 .NET Framework 4.0; MS Office 2010; SQL Server 2008 R2 Express Edition | Remember to mark resolved threads and rate useful posts.

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    11

    Re: Combo Boxes

    You make it seem so easy! That's a great help, thanks!

  5. #5
    Addicted Member sweet_dreams's Avatar
    Join Date
    Apr 2005
    Location
    Poland, Lodz
    Posts
    189

    Re: Combo Boxes

    i suggest you use this second code. and don't forget to tick thread as resolved (if of course it is resolved )

    regards,
    sweet_dreams
    using VB 2010 .NET Framework 4.0; MS Office 2010; SQL Server 2008 R2 Express Edition | Remember to mark resolved threads and rate useful posts.

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    11

    Re: Combo Boxes

    will do. off to try it now

  7. #7

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    11

    Re: [RESOLVED] Combo Boxes

    ahh damn.. marked it resolved when it isnt.

    I get "run time error '1004':

    Method 'Range' of object '_Global' failed."

  8. #8
    Addicted Member sweet_dreams's Avatar
    Join Date
    Apr 2005
    Location
    Poland, Lodz
    Posts
    189

    Re: [RESOLVED] Combo Boxes

    hm, on my PC this code works perfect:

    VB Code:
    1. Range(ComboBox1.Value).Select
    2. Range(ActiveCell, ActiveCell.Offset(0, 1)).ClearContents

    make sure that values of cell addresses in your RowSource property are correct

    s_d

  9. #9

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    11

    Re: [RESOLVED] Combo Boxes

    I have the control source set to Sheet!A1 and the rowsource to sheet!List

    where the list selects column A

    any problems?
    Last edited by TheRealDave; Mar 15th, 2006 at 04:53 PM.

  10. #10
    Addicted Member sweet_dreams's Avatar
    Join Date
    Apr 2005
    Location
    Poland, Lodz
    Posts
    189

    Re: [RESOLVED] Combo Boxes

    are you using any other code in your macro??? can you paste the whole code you are using???
    oh and have you changed the name of your combobox in the code???

    s_d

  11. #11

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    11

    Re: [RESOLVED] Combo Boxes

    that's the only code in there. It's very basic. I have different pages in a userform with the combo box and button on each page. I think the problem is selecting the cell somewhere but I just cant figure it out

  12. #12
    Addicted Member sweet_dreams's Avatar
    Join Date
    Apr 2005
    Location
    Poland, Lodz
    Posts
    189

    Re: [RESOLVED] Combo Boxes

    the code which I gave you is selectiond cell with address which was choosen in combobox: so if you clicked in your combobox A1 value, code selects A1 cell and then selects range A1:B1 and clear it's content.

    well, I don't have the foggiest idea what's wrong.

  13. #13

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    11

    Re: [RESOLVED] Combo Boxes

    Exactly what I was thinking. HOWEVER () this is for a school project and I can use this as part of my evaluation (if that's ok with you) stating that the code I used should have worked and I could then evaluate it to hell and write all this fancy stuff etc

    Still, I dont see why what you gave me shouldn't have worked. All the names, cells etc are all correct

    Thanks anyways

  14. #14
    Addicted Member sweet_dreams's Avatar
    Join Date
    Apr 2005
    Location
    Poland, Lodz
    Posts
    189

    Re: [RESOLVED] Combo Boxes

    you don't need to set control source property, row source is enought if you only want to assign list of values to your combobox

    hm I don't understand wha you mean by saying:
    where the list selects column A
    try row source property as for eg sheet1!a1-a11
    using VB 2010 .NET Framework 4.0; MS Office 2010; SQL Server 2008 R2 Express Edition | Remember to mark resolved threads and rate useful posts.

  15. #15

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    11

    Re: [RESOLVED] Combo Boxes

    what i meant by that is the list was the entire column A. This was because there was to be an unlimited ammount in that column and it had be selected within the system. I just tried removing the control source and am still getting the error. It's ok though, should be alright for me to just do it as it is.

  16. #16
    Addicted Member sweet_dreams's Avatar
    Join Date
    Apr 2005
    Location
    Poland, Lodz
    Posts
    189

    Re: [RESOLVED] Combo Boxes

    how did you create this list ??? I think here could be a problem

  17. #17

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    11

    Re: [RESOLVED] Combo Boxes

    Went to the sheet. Pressed A to select the whole column (which works fine in other places) and named it using the name box. Like I said, it's used as i list in validation on another page so there's no error in the list itself as far as I can tell.

  18. #18
    Addicted Member sweet_dreams's Avatar
    Join Date
    Apr 2005
    Location
    Poland, Lodz
    Posts
    189

    Re: [RESOLVED] Combo Boxes

    where do you exactly get the error message ???
    using VB 2010 .NET Framework 4.0; MS Office 2010; SQL Server 2008 R2 Express Edition | Remember to mark resolved threads and rate useful posts.

  19. #19

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    11

    Re: [RESOLVED] Combo Boxes

    Isn't that. I can still view the list. The correct property I have for that is "PERIPHERALS!PSR" where the sheet name is PERIPHERALS and the list is PSR.Not sure if this one's going to be solved

  20. #20
    Addicted Member sweet_dreams's Avatar
    Join Date
    Apr 2005
    Location
    Poland, Lodz
    Posts
    189

    Re: Combo Boxes

    maybe attach your excel file so I can take a look at it in the morning I'm too tired to do this now.

    regards,
    sweet_dreams

  21. #21

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    11

    Re: Combo Boxes

    That will be a problem as i don't have it with me. It's on a different computer that i have remote access to and no way of moving it, sorry. I think i'm just going to leave it and see how it goes..

Posting Permissions

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



Click Here to Expand Forum to Full Width