Userform output range

VanillaSky

New Member
Joined
Sep 9, 2017
Messages
8
Hello.

I am attempting to create table as below:

a2098645846d79f5a8596cb47f8097f7.png


I've created userform to input new data for PI_Case to Opening_Date cells. However I can't make it work properly, as userform is looking for empty rows
to insert new entries. Please note the code below:
Code:
<code>Sub CommandButton_Submit_Click()

Dim iRow As Long

Dim ws As Worksheet
Set ws = Worksheets("List")

myDate = Date

'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
    SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1

'check for a Name number
If Trim(Me.TextBox_Company_Name.Value) = "" Then
  Me.TextBox_Company_Name.SetFocus
  MsgBox "Please complete the form"
  Exit Sub
End If

'copy the data to the database

ws.Cells(iRow, 1).Value = Me.TextBox_PI_Case.Value
ws.Cells(iRow, 2).Value = Me.TextBox_Company_Name.Value
ws.Cells(iRow, 3).Value = Me.TextBox_Status.Value
ws.Cells(iRow, 4).Value = Me.TextBox_RoR.Value
ws.Cells(iRow, 5).Value = Me.TextBox_Comments.Value
ws.Cells(iRow, 6).Value = myDate
MsgBox "Data added", vbOKOnly + vbInformation, "Data Added"
'clear the data
Me.TextBox_PI_Case.Value = ""
Me.TextBox_Company_Name.Value = ""
Me.TextBox_Status.Value = ""
Me.TextBox_RoR.Value = ""
Me.TextBox_Comments.Value = ""
Me.TextBox_PI_Case.SetFocus

End Sub
</code>

I assume that I should specify Range for data output for PI_Case to Opening_Data columns, however my poor knowledge does not allow me to do that. :LOL:

Is there any possibility to make it work or VBA only allows to insert data from userform starting with first column?

Thank you in advance.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try this:
Code:
Dim irow As Long
irow = Cells(Rows.Count, "A").End(xlUp).Row + 1
 
Upvote 0
As I said i want to enter new data in PI_Case to Opening_Date cells. So that would be from 2nd to 7th column.

Sorry if I wasn't clear ;)
 
Upvote 0
Solution:

Code:
Private Sub OutPutData()
    Dim NextRow As Range
     
    Set NextRow = Worksheets("List").Cells(Rows.Count, "B").End(xlUp).Offset(1).Resize(1, 6)
    With Me
    
        NextRow.Cells(1) = .TextBox_PI_Case
        NextRow.Cells(2) = .TextBox_Company_Name
        NextRow.Cells(3) = "NEW"
        NextRow.Cells(4) = .TextBox_RoR
        NextRow.Cells(5) = .TextBox_Comments
        NextRow.Cells(6) = Date
    End With
End Sub


Private Sub ClearData() 'Better = "ClearDataControls," or "Clear_ioCtrls."
    With Me
        .TextBox_PI_Case = ""
        .TextBox_Company_Name = ""
        .TextBox_RoR = ""
        .TextBox_Comments = ""
        .TextBox_PI_Case.SetFocus
    End With
End Sub


 
Sub CommandButton_Submit_Click()
     
     'check for a Name number
    If Trim(Me.TextBox_Company_Name.Value) = "" Then
        Me.TextBox_Company_Name.SetFocus
        MsgBox "Please complete the form"
        Exit Sub
    End If
     
     'copy the data to the database
    OutPutData
     
    MsgBox "Data added", vbOKOnly + vbInformation, "Data Added"
     
     'clear the data
    ClearData
     
End Sub


Private Sub CommandButton_Cancel_Click()
Unload Me
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,390
Messages
6,124,667
Members
449,178
Latest member
Emilou

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