Userform info doesn't move past first row?

coffeeandbooks

New Member
Joined
May 2, 2016
Messages
1
So I'm super new to VBA :eek: (hey but I'm learning!)

The goal of the code that I'm writing is to create a simple database to track new corporate accounts and sales based on office location. (So nothing fancy).

However, as the user fills out the user form, it only fills out the first now (doesn't move onto the next row, etc)...

Here's the code I have written so far:
Code:
Sub CommandButton1_Click()
Dim i As Integer
i = 1
While ThisWorkbook.Worksheets("Sheet1").Range("A" & i).Value <> ""
i = i + 1
Wend
ThisWorkbook.Worksheets("Sheet1").Range("B" & i).Value = ComboBox1.Value
ThisWorkbook.Worksheets("Sheet1").Range("C" & i).Value = ComboBox2.Value
ThisWorkbook.Worksheets("Sheet1").Range("D" & i).Value = TextBox1.Value
ThisWorkbook.Worksheets("Sheet1").Range("E" & i).Value = TextBox2.Value
ThisWorkbook.Worksheets("Sheet1").Range("F" & i).Value = TextBox3.Value
ThisWorkbook.Worksheets("Sheet1").Range("G" & i).Value = TextBox4.Value
ThisWorkbook.Worksheets("Sheet1").Range("H" & i).Value = TextBox5.Value
End Sub


Sub UserForm_Initialize()
ComboBox1.List = Array("001 - S. Venice", "056 - Seminole", "042 - Gateway")
ComboBox2.List = Array("1:00PM", "5:00PM", "9:00PM")
End Sub
Thanks in advance!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Hi coffeeandbooks,

Welcome to MrExcel!!

It looks like the issue is that you're scrolling down column A to find the first blank row but you're populating columns B to H (inclusive). Assuming that is the issue try this:

Code:
Option Explicit
Sub CommandButton1_Click()
    
    Dim i As Long
    
    With ThisWorkbook.Worksheets("Sheet1")
        i = .Range("B:H").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
        .Range("B" & i).Value = ComboBox1.Value
        .Range("C" & i).Value = ComboBox2.Value
        .Range("D" & i).Value = TextBox1.Value
        .Range("E" & i).Value = TextBox2.Value
        .Range("F" & i).Value = TextBox3.Value
        .Range("G" & i).Value = TextBox4.Value
        .Range("H" & i).Value = TextBox5.Value
    End With
    
End Sub

Regards,

Robert
 
Upvote 0

Forum statistics

Threads
1,215,379
Messages
6,124,610
Members
449,174
Latest member
ExcelfromGermany

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