Consulting

Results 1 to 6 of 6

Thread: Using userform VBA to create a list

  1. #1
    VBAX Newbie
    Joined
    Jan 2020
    Posts
    3
    Location

    Using userform VBA to create a list

    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.

  2. #2
    VBAX Mentor Logit's Avatar
    Joined
    Sep 2016
    Posts
    483
    Location
    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
    Attached Files Attached Files

  3. #3
    VBAX Newbie
    Joined
    Jan 2020
    Posts
    3
    Location
    Thanks mate, pretty much covered it, what about if i wanted to start that list at cell d7?

  4. #4
    VBAX Mentor Logit's Avatar
    Joined
    Sep 2016
    Posts
    483
    Location
    .
    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

  5. #5
    Knowledge Base Approver VBAX Guru
    Joined
    Apr 2012
    Posts
    4,892
    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,txtSurName,"snb","much simpler")  
    End Sub

  6. #6
    VBAX Mentor Logit's Avatar
    Joined
    Sep 2016
    Posts
    483
    Location
    Quote Originally Posted by snb View Post
    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,txtSurName,"snb","much simpler")  
    End Sub

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •