+ Reply to Thread
Results 1 to 13 of 13

code for userform to delete combo box value from dynamic range & move column up

  1. #1
    Forum Contributor
    Join Date
    04-14-2013
    Location
    Ky
    MS-Off Ver
    Excel 2013
    Posts
    344

    code for userform to delete combo box value from dynamic range & move column up

    In my workbook, I have a very simple userform to add employees to the next empty row on ws2, "Admin Menu". This list of employees is a named range "EmpList".

    On the same sheet, I have another simple userform that will "delete" an employee from the dynamic range. Actually, on my "Data" sheet, ws3, the code just finds the name of the employee and changes it to "Former Employee" - so we don't lose the rest of the data input under that employee's name. But I do need to actually delete the employee from the Employee list on ws2, and move any employee names that were under the deleted employee up. I cannot delete the entire row because of other data in other columns on that sheet. Here's me code for replacing the employee name - but I have no idea where to start on deleting the employee (cbo5) from my dynamic range, "EmpList," other than I need to select the range and probably use delete Shift:= xlup...

    Please Login or Register  to view this content.
    Sorry I cannot post the workbook right now but thanks to anyone who has a suggestion.

    -HeyInKy

  2. #2
    Registered User
    Join Date
    08-19-2014
    Location
    Pittsburgh, Pennsylvania
    MS-Off Ver
    2010
    Posts
    45

    Re: code for userform to delete combo box value from dynamic range & move column up

    but I have no idea where to start on deleting the employee (cbo5) from my dynamic range, "EmpList," other than I need to select the range and probably use delete Shift:= xlup...
    Is there a reason that you cannot use this method?
    Untested:
    Please Login or Register  to view this content.


    *Add reputation if this was helpful.

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

    Re: code for userform to delete combo box value from dynamic range & move column up

    How are you populating the combobox from the dynamic range?

    Is the employee you want to delete from the list on ws2 selected in the combobox?
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    08-19-2014
    Location
    Pittsburgh, Pennsylvania
    MS-Off Ver
    2010
    Posts
    45

    Re: code for userform to delete combo box value from dynamic range & move column up

    Norie, I'm assuming OP has already successfully tested value in the ComboBox, as that value is being used programmatically to look to a range and change the value to "Former Employee".
    OP is struggling to take that value cbo5 find it in a range, delete just that name, and shift the rest of the range up.

  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: code for userform to delete combo box value from dynamic range & move column up

    If cbo5 has been populated from the dynamic range it should be straightforward to find the employee if they are selected in the combobox as the ListIndex of the combobox will directly correspond to the row within the range.

    The reason I asked how the OP has used the range to populate the range is because if they have used RowSource there could be problems.

  6. #6
    Forum Contributor
    Join Date
    04-14-2013
    Location
    Ky
    MS-Off Ver
    Excel 2013
    Posts
    344

    Re: code for userform to delete combo box value from dynamic range & move column up

    @Jamie.Ries

    No reason I couldn't use that method, other than I'm super new and very green at VBA - kind of learning as I go... I can use Google well enough, but without formally learning VBA (something on my ToDo list!), I struggle adapting examples to my own code and keeping the syntax structure.

    By the way on your code - don't I need to define C? As what, Integer?

    @Norie, per your earlier suggestions, it's not populated by RowSource, but rather:

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    04-14-2013
    Location
    Ky
    MS-Off Ver
    Excel 2013
    Posts
    344

    Re: code for userform to delete combo box value from dynamic range & move column up

    ...and @Norie,

    see my struggles with populating the combo box in this thread here

  8. #8
    Registered User
    Join Date
    08-19-2014
    Location
    Pittsburgh, Pennsylvania
    MS-Off Ver
    2010
    Posts
    45

    Re: code for userform to delete combo box value from dynamic range & move column up

    Got ya! You were pretty well on your way with the post, I just figured maybe there was a reason you couldn't use that particular method.
    No need to set dimension!

    Best of luck to you!

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

    Re: code for userform to delete combo box value from dynamic range & move column up

    The code to populate the combobox should go in a userform's initialize event, definitely not in the change event of the combobox.

    You actually posted code for the Initialize event, was there a problem with it?

    Also, what formula are you using for the dynamic range?

    Are you using the dynamic range elsewhere, eg on a worksheet?

    If you aren't then you could probably get the list of employees in code.

    By the way, why are you using a separate form for delete employees?

    Couldn't you use your main form?

  10. #10
    Forum Contributor
    Join Date
    04-14-2013
    Location
    Ky
    MS-Off Ver
    Excel 2013
    Posts
    344

    Re: code for userform to delete combo box value from dynamic range & move column up

    I think I can post my workbook - had to sanitize a bit....

    And I told a white lie on my post above... if you look at the attachment, you'll see "EmpList" is used as

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    but to delete, I'm using "EmpDelList"

    Formula: copy to clipboard
    Please Login or Register  to view this content.

    because the first value, $B$2 (Former Employee) needs to always be present...

    And I use the initialize command in my QAReviewForm... maybe I should change all that?
    Attached Files Attached Files

  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: code for userform to delete combo box value from dynamic range & move column up

    Put this in the code for the userform DeleteEmp,
    Please Login or Register  to view this content.
    and delete this.
    Please Login or Register  to view this content.
    Now the combobox will be populate as soon as you open the userform.

    As for setting focus on cbo5 when the userform open try this.

    1 Right click the form.

    2 Select Tab Order.

    3 Move the controls Up/Down as appropriate, eg if you want cbo5 to have focus when the userform opens move it right to the top.

    While I'm here, there's a problem on the EmpAdd form.

    You've named a button on that form EmpAdd.

    That's not a good, try changing the button name to something like btnEmpAdd


    Back to deleting the employee.

    Change the code for the DelEmp button to this.
    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    04-14-2013
    Location
    Ky
    MS-Off Ver
    Excel 2013
    Posts
    344

    Re: code for userform to delete combo box value from dynamic range & move column up

    Thanks Norie! 5 Stars to you!

    I'll mark this thread solved - but while I'm here, let me ask, when I delete, say for example, Beth from my employee list - it messes up formula in column A

    Formula: copy to clipboard
    Please Login or Register  to view this content.

    which I used as a record number for the number of employees. Is there a VBA code I could use (it would have to go in the EmpAdd form) to create a sequential, numeric record #?

    Thanks again!

    -HeyInKy

  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: code for userform to delete combo box value from dynamic range & move column up

    Yes I saw that.

    It should be quite simple to fix, all you need is code to copy the formula down from A2 (or A3?).

    Or code to fill in the formula in the required no of rows.

    I think the latter might be easier.

+ 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] Populate userform combo box with named dynamic list
    By HeyInKy in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-28-2014, 05:17 PM
  2. Userform with dynamic combo boxes and autofilters
    By alfordtp in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-17-2014, 10:29 PM
  3. Replies: 0
    Last Post: 06-25-2013, 09:42 AM
  4. [SOLVED] Dynamic Row source for Combo box on Userform.
    By excelkeechak in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-15-2012, 09:58 PM
  5. Move selected column to end of dynamic range
    By RedWing in forum Excel General
    Replies: 1
    Last Post: 09-10-2011, 05:19 PM

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