+ Reply to Thread
Results 1 to 3 of 3

Data from a Userform is added to the top if the worksheet

Hybrid View

n_malley Data from a Userform is added... 01-11-2013, 07:32 AM
Norie Re: Data from a Userform is... 01-11-2013, 07:44 AM
n_malley Re: Data from a Userform is... 01-11-2013, 07:50 AM
  1. #1
    Registered User
    Join Date
    12-28-2012
    Location
    Manchester, England
    MS-Off Ver
    Excel 2003
    Posts
    5

    Data from a Userform is added to the top if the worksheet

    Hi All,

    i'm new to the forum so apologies if i have added this incorrectly

    i'm creating a form which added information to the select worksheet- when the worksheet is selected the last blank row is highlighted.
    so far the combo box highlights the correct worksheet and goes to the last blank row but the command button add the data to the top of the worksheet. i need it to be added to the last blank row.


    below is my code (sorry if its a mess i'm brushing up on code i have used for years )

    Option Explicit
    Dim WkSht As Worksheet
    Dim lngLastRow As Long
    Dim rngInput As Range
    
    
    
    Private Sub ComboBox1_Click()
    Application.ScreenUpdating = 0
    Sheets(ComboBox1.Value).Visible = True
    Application.Goto Sheets(ComboBox1.Value).[a1], True
    Application.ScreenUpdating = 1
    
    
    End Sub
    
    Private Sub CommandButton1_Click()
    lngLastRow = ActiveSheet.UsedRange.Rows.Count + 1
    Set rngInput = Cells(lngLastRow, 2).End(xlUp).Offset(1, 0)
    rngInput.Select
    Range("b1") = TextBox1.Text
    Range("c1") = TextBox2.Text
    Range("d1") = TextBox3.Text
    Range("e1") = TextBox4.Text
    
    End Sub
    
    
    Private Sub UserForm_Initialize()
        For Each WkSht In ThisWorkbook.Worksheets
            ComboBox1.AddItem (WkSht.Name)
        Next WkSht
    End Sub
    any help would be fantastic.
    thanks!

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Data from a Userform is added to the top if the worksheet

    Try this.
    Private Sub CommandButton1_Click()
    
      Set rngInput = Cells(Rows.Count, 2).End(xlUp).Offset(1, 0)
    
      With rngInput
        .Value = TextBox1.Text
        .Offset(,1) = Textbox2.Text
        .Offset(,2) = Textbox3.Text
        .Offset(,3) = Textbox4.Text
       End With
    
    End Sub
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    12-28-2012
    Location
    Manchester, England
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Data from a Userform is added to the top if the worksheet

    Thank you ,

    works perfectly much appreciated!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1