Ask Experts Questions for FREE Help !
Ask
    dannac's Avatar
    dannac Posts: 267, Reputation: 9
    Full Member
     
    #1

    Jan 26, 2011, 01:32 PM
    Code works but paste to wrong location
    I have a user form that inputs data to the next available row.

    It starts the data in col A... I need it to start in col B.

    Private Sub CommandButton1_Click()
    ' Make sure Sheet1 is active
    Sheets("2011").Activate

    ' Determine next empty row
    'Nextrow = _
    'Application.WorksheetFunction.CountA(Range("A:A") ) + 1

    nextrow = Range("B" & Rows.Count).End(xlUp).Offset(1)

    ' Transfers the name
    Cells(nextrow, 2) = TextBox1.Text
    Cells(nextrow, 3) = TextBox2.Text
    Cells(nextrow, 4) = TextBox3.Text
    Cells(nextrow, 5) = TextBox4.Text
    Cells(nextrow, 6) = TextBox12.Text
    Cells(nextrow, 7) = TextBox5.Text
    Cells(nextrow, 8) = TextBox6.Text
    Cells(nextrow, 9) = TextBox7.Text
    Cells(nextrow, 10) = TextBox8.Text
    Cells(nextrow, 11) = TextBox9.Text
    Cells(nextrow, 12) = TextBox10.Text
    Cells(nextrow, 13) = TextBox11.Text
    Cells(nextrow, 14) = ComboBox1.Text
    Cells(nextrow, 15) = ComboBox2.Text

    ' Clears form for next entry
    TextBox1.Text = ""
    TextBox2.Text = ""
    TextBox3.Text = ""
    TextBox4.Text = ""
    TextBox5.Text = ""
    TextBox6.Text = ""
    TextBox7.Text = ""
    TextBox8.Text = ""
    TextBox9.Text = ""
    TextBox10.Text = ""
    TextBox11.Text = ""
    TextBox1.SetFocus

    End Sub
    I thought this line would have it start in col B
    Cells(nextrow, 2) = TextBox1.Text
    JBeaucaire's Avatar
    JBeaucaire Posts: 5,426, Reputation: 997
    Software Expert
     
    #2

    Jan 26, 2011, 05:45 PM
    First, use CODE tags, not QUOTE tags:

    Quote Originally Posted by dannac View Post
    It starts the data in col A .... I need it to start in col B.

    Code:
    Cells(nextrow, 2) = TextBox1.Text
    I thought this line would have it start in col B
    That line of code DOES insert a value in column B.
    dannac's Avatar
    dannac Posts: 267, Reputation: 9
    Full Member
     
    #3

    Jan 27, 2011, 06:26 AM
    Hi Jerry... I cannot find what's wrong. It still paste data starting in col A.

    Code:
    '   Make sure Sheet1 is active
        Sheets("2011").Activate
        
    '   Determine next empty row
        'Nextrow = _
        'Application.WorksheetFunction.CountA(Range("A:A")) + 1
        
        nextrow = Range("B" & Rows.Count).End(xlUp).Offset(1)
        
    '   Transfers the name
        Cells(nextrow, 2) = TextBox1.Text
        Cells(nextrow, 3) = TextBox2.Text
        Cells(nextrow, 4) = TextBox3.Text
        Cells(nextrow, 5) = TextBox4.Text
        Cells(nextrow, 6) = TextBox12.Text
    The last line in code above was because I added a textbox after the form had been made a few months... to separate First & Last Names.



    JBeaucaire's Avatar
    JBeaucaire Posts: 5,426, Reputation: 997
    Software Expert
     
    #4

    Jan 27, 2011, 07:00 AM

    There's nothing in this code that puts data in column A.
    dannac's Avatar
    dannac Posts: 267, Reputation: 9
    Full Member
     
    #5

    Jan 27, 2011, 07:36 AM

    LOL... wish you could tell my computer that... cause it's not listening to me.

    I'm stuck.
    dannac's Avatar
    dannac Posts: 267, Reputation: 9
    Full Member
     
    #6

    Jan 27, 2011, 08:05 AM

    I'm noticing the code is in properties for sheet 2011
    And same code is in properties for the userform.

    Should it be in both ?
    dannac's Avatar
    dannac Posts: 267, Reputation: 9
    Full Member
     
    #7

    Jan 27, 2011, 08:17 AM
    Now, when clicking add button it gives debug error and highlights the line :

    Cells(nextrow, 2) = TextBox1.Text

    I include file as attachment.
    Attached Files
  1. File Type: xls testform2011.xls (45.5 KB, 114 views)
  2. JBeaucaire's Avatar
    JBeaucaire Posts: 5,426, Reputation: 997
    Software Expert
     
    #8

    Jan 28, 2011, 11:34 AM
    Quote Originally Posted by dannac View Post
    I'm noticing the code is in properties for sheet 2011
    and same code is in properties for the userform.

    Should it be in both ?
    Command Button code for a form should only be in the form module.
    JBeaucaire's Avatar
    JBeaucaire Posts: 5,426, Reputation: 997
    Software Expert
     
    #9

    Jan 28, 2011, 11:41 AM

    You didn't resolve the NEXTROW as a number:
    Code:
    '   Determine next empty row
        nextrow = Range("B" & Rows.Count).End(xlUp).Offset(1).Row

    After fixing that, I ran the form and it inserted values in columns B:O.
    Attached Files
  3. File Type: xls Testform2011a.xls (30.0 KB, 156 views)
  4. dannac's Avatar
    dannac Posts: 267, Reputation: 9
    Full Member
     
    #10

    Jan 28, 2011, 01:25 PM

    Thanks Jerry.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search


Check out some similar questions!

Service panel location code for upstate NY [ 2 Answers ]

I am upgrading my service and am wondering if the panel box needs to be installed on an exterior wall? I plan on leaving the existing service in place while running all new wire to the new panel box. The existing panel box is in a corner on the exterior wall, can I put the new box on the interior...

Works 7.0 Default File Location [ 3 Answers ]

Works 7.0. I have two hard drives with my files on the E: drive. Works always looks to C:/MyDocuments. I want to change it to look at E:/MyDocuments. Easy to do in Office. How can it be done in Works ?

Wrong furnace location [ 1 Answers ]

Hello, I wonder if there is any limit (or standards?) in diffrence between basement and first floor temperature. My basement is 3 degree Celsius warmer than first floor due to very long heating line from one basement corner to another. It is 1 year old home with furnace installed in a wrong...

Code Reader Location Nissan [ 1 Answers ]

Does anyone know where the code reader connector is located on a 2001 Nissan Sentra?

MS Works 7.0 Default File Location [ 2 Answers ]

How do I set or change the default file location in MS Works 7.0 ?


View more questions Search