VBA Userform populates next blank row

championem31

New Member
Joined
Aug 16, 2013
Messages
3
So I have a VBA Userform with combo boxes and textboxes. I already had the combo boxes set up to populate a cell in the workbook as an array, but I'm having problems populating the next blank row. I have it set up for data entry, so a person could enter multiple events without exiting the form. However, the way its set up now, it occasionally overwrites data from an already filled out form. No fields are required. How can I get it to go to the next completely blank row? Right now I keep getting errors because it's stuck in a loop. Please help!!! Thank you!

Code:
Private Sub btnsave_click()
Dim irow As Long
Dim ws As Worksheet
Dim arrValues()


    Set ws = Worksheets("13-14")
    
    With ws
        ' find first blank row in database
       irow = .Cells(Rows.Count, 3).End(xlUp).Offset(1, 0).Row


.Cells(irow, 1).Value = Me.TypePresEvent.Value
.Cells(irow, 2).Value = Me.Topic.Value
.Cells(irow, 4).Value = Me.Class.Value
.Cells(irow, 5).Value = Me.Location.Value
.Cells(irow, 6).Value = Me.Attendance.Value
.Cells(irow, 8).Value = Me.Notes.Value


      
                
For I = 0 To Presenters.ListCount - 1
            If Presenters.Selected(I) Then
                ReDim Preserve arrValues(X)
                arrValues(X) = Presenters.List(I)
                X = X + 1
                Presenters.Selected(I) = False
            End If


        Next I
With ws


        .Range("c" & irow).Value = Join(arrValues, ",")


        
        
      
        
                For I = 0 To Items.ListCount - 1
           If Items.Selected(I) Then
                ReDim Preserve arrValues(y)
                arrValues(y) = Items.List(I)
                y = y + 1
                Items.Selected(I) = False
              End If
              Next I
              
          
With ws
        .Range("G" & irow).Value = Join(arrValues, ",")
 
   




End If




   Next I


     
    End With


    TypePresEvent.Value = ""
    Topic.Value = ""
    Class.Value = ""
    Location.Value = ""
    Attendance.Value = ""
    Notes.Value = ""








End If
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
You've chosen column C as your index column for your row count:

irow = .Cells(Rows.Count, 3).End(xlUp).Offset(1, 0).Row

When choosing this column, you need to be 100% positive that it will ALWAYS have a value for EVERY row of data. If not, you need to choose another column, AND, you need to put in some error checking to force the user to enter a value for that column.
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top