PDA

View Full Version : Using userform VBA to create a list



Fletcher
01-13-2020, 06:29 PM
Hi,
I have a user form which outputs 4 piece of data in the same row,
ever time there is a break down i want to add another row of data however not override the line just entered, can you provide some help.

Logit
01-13-2020, 07:41 PM
Option Explicit
Private Sub btnCancel_Click()
Unload Me
End Sub


Private Sub btnOK_Click()
Dim ws As Worksheet
Set ws = ActiveSheet
Dim newRow As Long

newRow = Application.WorksheetFunction.CountA(ws.Range("A:A")) + 1

'The next two lines can be expanded as many times as needed for all the entry fields in your project

ws.Cells(newRow, 1).Value = Me.txtFirstName.Value
ws.Cells(newRow, 2).Value = Me.txtSurname.Value

End Sub
Sub CommandButton1_Click()
Selection.EntireRow.Delete
End Sub

Fletcher
01-13-2020, 07:57 PM
Thanks mate, pretty much covered it, what about if i wanted to start that list at cell d7?

Logit
01-14-2020, 05:19 PM
.


Option Explicit


Private Sub btnCancel_Click()
Unload Me
End Sub


Private Sub btnOK_Click()
Dim ws As Worksheet
Set ws = ActiveSheet
Dim newRow As Long

newRow = Application.WorksheetFunction.CountA(ws.Range("D:D")) + 1

'The next two lines can be expanded as many times as needed for all the entry fields in your project


ws.Cells(newRow, 4).Value = Me.txtFirstName.Value
ws.Cells(newRow, 5).Value = Me.txtSurname.Value

End Sub
Sub CommandButton1_Click()
Selection.EntireRow.Delete
End Sub

snb
01-15-2020, 08:43 AM
Do you guys ever use the search function in this Forum ?


Private Sub btnOK_Click()
cells(rows.count,4).end(xlup).offset(1).resize(,4)=array(txtFirstName,txtSu rName,"snb","much simpler")
End Sub

Logit
01-15-2020, 12:05 PM
Do you guys ever use the search function in this Forum ?


Private Sub btnOK_Click()
cells(rows.count,4).end(xlup).offset(1).resize(,4)=array(txtFirstName,txtSu rName,"snb","much simpler")
End Sub


I can only speak for myself .... first time I've seen that. Thank you.