+ Reply to Thread
Results 1 to 17 of 17

Edit/Update list from userform (auto alphabetized)

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-09-2009
    Location
    Columbus. Ohio
    MS-Off Ver
    Excel 2000
    Posts
    199

    Edit/Update list from userform (auto alphabetized)

    As the title suggests I have a sheet that creates a list of columns that may need to be updated or edited as necessary. Column A is a list of names that are alphabetized automaticaly from column D, so any change in column D would need to be reflected in column A. The attached sheet will (I hope) make things clearer.

    Thanks

    Jim O
    Attached Files Attached Files
    Last edited by Jogier505; 12-02-2009 at 09:36 PM.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Edit/Update list from userform (auto alphabetized)

    Hi

    Sorting updated data:
    As you are using an event to sort the data in column A, why not add an instruction to copy the data from column D into column A before the sort? That way you (a) don't have to add the data to both columns, and (b) when you have data in column D updated, it will be selected and sorted.

    Updating Data:
    Your form really only has the option to add new data, or close. Are you requesting that your form is enhanced to have an update facility?

    rylo

  3. #3
    Forum Contributor
    Join Date
    09-09-2009
    Location
    Columbus. Ohio
    MS-Off Ver
    Excel 2000
    Posts
    199

    Re: Edit/Update list from userform (auto alphabetized)

    rylo,

    This sheet is part of a game pool, and the names are people who have entered. My thinking on this was that since the names are not entered at the same time and not everyone would pay their entry fee at the same time I needed a way to track and update as necessary. The plan as I see it is that as names come in they are entered into column "D". If the entrant has paid their fee, supplied an email address and given a tie breaker score that would be entered as well at that time. For the entries who pay later or supply information later I need a way to update that.

    The numbers in column "C" are used as a reference for a list of entries not payed and the letters in column "E" are for a column lookup elsewhere in the spreadsheet.

    Their may be 50 to 60 or more entrants and column "A" is alphebetized to make scrolling down the list easier.

    My thinking was that if a correction in spelling from column "D" needed to be made it would need to be reflected in column "A" or the lookup (see dropdown box in the green cell) would not work.

    It may be that that will create too many problems in which case just being able to edit/update columns "F", "G", and "H" would be fine.

    I am not very savy in the ways of VBA and any assistance would be a big plus.

    Thanks for your response.

    Jim O

  4. #4
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Edit/Update list from userform (auto alphabetized)

    Jim

    If you change your change event to
    Private Sub Worksheet_Change(ByVal Target As Range)
      On Error GoTo errhand
      Application.EnableEvents = False
      Range("D2", Range("D2").End(xlDown)).Copy Destination:=Range("A2")
    
      Columns(1).Sort Key1:=Range("A1"), Order1:=xlAscending, _
        Header:=xlGuess, OrderCustom:=1, _
        MatchCase:=False, Orientation:=xlTopToBottom
    errhand:
      Application.EnableEvents = True
    End Sub
    then changes made to column D will be reflected in column A.

    Your form only has one option - add a new entry.

    Do you want to have 2 different forms - one for add new entry, second for amend existing entry? Or do you want to have one form with 2 different options - add new or update?

    rylo

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Edit/Update list from userform (auto alphabetized)

    Hello Jogier505,

    I have revised your User Form and code to do what you asked. Column "A" has now been eliminated because the entries are now sorted when the user form opens, a new name is added, or a name is deleted. TextBox1 has been replaced by ComboBox1. This allows the user to either start typing in a name or select a name using the drop down.

    Column "B" no longer contains any formulae. This column is filled automatically by the macro whenever the data changes. The formulae in column "E" remain intact.

    Since you are opening the UserForm as non modal, I have added a code module to make the User Form act and look like a standard window. I have attached a jpg so you can see what the new form it looks like. The attached workbook contains all the changes.

    User Form Code
    Public R As Long
    Public Wks As Excel.Worksheet
    
    Sub LoadNames()
     'FILL THE COMBOBOX, SORT THE NAMES, AND ADD SEQUENTIAL ENTRY NUMBERS
     
      Dim Cell As Range
      Dim N As Long
      Dim Rng As Range
      Dim RngEnd As Range
          
        Set Rng = Wks.Range("D2:H2")
        Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp)
        Set Rng = IIf(RngEnd.Row < Rng.Row, Rng, Wks.Range(Rng, RngEnd))
        
        Application.ScreenUpdating = False
        
          Rng.Sort Key1:=Rng.Cells(1, 1), Order1:=xlAscending, Header:=xlNo, _
                   Orientation:=xlTopToBottom, MatchCase:=False
          
          ComboBox1.Clear
          For Each Cell In Rng.Columns(1).Cells
            N = N + 1
            Cell.Offset(0, -1) = N
            With ComboBox1
              .AddItem
                .List(.ListCount - 1, 0) = Cell.Value
                .List(.ListCount - 1, 1) = Cell.Row
            End With
          Next Cell
        
        Application.ScreenUpdating = True
        
    End Sub
    
    Private Sub CmdAdd_Click()
     'ADD NEW NAME
      
        If ComboBox1.Value = "" Then
           MsgBox "You must enter a name.", vbInformation
           Exit Sub
        End If
       
        Set Rng = Wks.Range("C2")
        Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp)
        Set Rng = IIf(RngEnd.Row < Rng.Row, Rng, Wks.Range(RngEnd, Rng))
              
       'switch off ScreenUpdating to speed up code & prevent flickering
        Application.ScreenUpdating = False
    
       'First empty row in database
        R = Rng.Row + Rng.Rows.Count
    
       'copy the data to the database
        With Wks.Rows(R).Cells
          .Item(1, 4).Value = ComboBox1.Value
          .Item(1, 5).FormulaR1C1 = "=SUBSTITUTE(ADDRESS(1, 2 + 2 * ROWS(R1C:RC), 4), 1, """")"
          .Item(1, 6).Value = TextBox2.Value
          .Item(1, 7).Value = TextBox3.Value
            If CheckBox1 = True Then
               .Item(1, 8) = "PD"
            Else
               .Item(1, 8) = "No"
            End If
        End With
    
        LoadNames
        
    End Sub
    
    Private Sub ComboBox1_Click()
     'SELECT A NAME
      
        R = CLng(ComboBox1.List(ComboBox1.ListIndex, 1))
        
          With Wks
            ComboBox1 = .Cells(R, "D")
            TextBox2 = .Cells(R, "F")
            TextBox3 = .Cells(R, "G")
              If CheckBox1.Value = True Then
                 .Cells(R, "H") = "PD"
              Else
                 .Cells(R, "H") = "No"
              End If
          End With
          
    End Sub
    
    Private Sub CommandButton1_Click()
     'UPDATE WORKSHEET DATA
        
        If ComboBox1.ListIndex < 0 Then
           MsgBox "You must first select a name.", vbInformation
           Exit Sub
        End If
        
        R = CLng(ComboBox1.List(ComboBox1.ListIndex, 1))
        
          With Wks
            .Cells(R, "D") = ComboBox1
            .Cells(R, "F") = TextBox2
            .Cells(R, "G") = TextBox3
              If CheckBox1.Value = True Then
                 .Cells(R, "H") = "PD"
              Else
                 .Cells(R, "H") = "No"
              End If
          End With
          
    End Sub
    
    Private Sub CommandButton2_Click()
     'DELETE ENTRY
        
          If ComboBox1.ListIndex < 0 Then
             MsgBox "You must first select a name.", vbInformation
             Exit Sub
          End If
          
          With ComboBox1
            R = CLng(.List(.ListIndex, 1))
          End With
          
          TextBox1 = ""
          TextBox2 = ""
          TextBox3 = ""
          CheckBox1.Value = False
          
          Wks.Rows(R).EntireRow.Delete Shift:=xlShiftUp
          LoadNames
        
    End Sub
    
    Private Sub UserForm_Activate()
    
     'Add buttons to UserForm's title bar
      AddToForm MIN_BOX
      AddToForm MAX_BOX
      
     'Initialize the public variable Wks
      Set Wks = Worksheets("Lists")
      
     'Activate the worksheet and select "C2"
      Wks.Activate
      Wks.Range("C2").Select
    
     'Fill ComboBox1
      LoadNames
      
    End Sub
    Clear Player Data Macro
    Sub ClearPlayerData()
      
      Dim Rng As Range
      Dim RngEnd As Range
    
        With Worksheets("Lists")
          Set Rng = .Range("C2:H2")
          Set RngEnd = .Cells(Rows.Count, Rng.Column).End(xlUp)
            If RngEnd.Row < Rng.Row Then Exit Sub  'No names have been entered
          .Range(Rng, RngEnd).Clear
        End With
        
    End Sub
    Attached Images Attached Images
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  6. #6
    Forum Contributor
    Join Date
    09-09-2009
    Location
    Columbus. Ohio
    MS-Off Ver
    Excel 2000
    Posts
    199

    Re: Edit/Update list from userform (auto alphabetized)

    Leith,

    That is what I was hoping to achive. However I have found a few minor glitches.

    1. It will not allow me to edit an existing name. It will only accept a new entry.

    2. When a name is added or an entry is updated the text boxes and check box do not clear. so if you are not careful the next entry will have the same data.

    3. I need to limit the range when deleting an entry to columns C thru H not the entire row.

    That aside it is beautiful.

    Jim O

+ 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