excel vba write from userform to sheet

Posted on 2012-09-06
Last Modified: 2012-09-06
hi experts,

When i run this code the sheet isn't filled. can someone help me with this?
Private Sub butAdd_Click()

    Dim x As Long
    With Sheets("DividedPD's")
    x = Cells(Rows.Count, "A").End(xlUp).Row + 1

    .Range("A" & x) = TextBox1
    .Range("B" & x) = TextBox2
    .Range("C" & x) = TextBox3
    .Range("D" & x) = TextBox5
    .Range("E" & x) = TextBox6
    .Range("F" & x) = TextBox7
    .Range("G" & x) = TextBox9
    .Range("H" & x) = TextBox10
    .Range("I" & x) = TextBox11
    End With
End Sub

Open in new window

Thanks in advance:)
Question by:MarkVrenken
    LVL 1

    Author Comment

    Oh and ps i'd rather not activate the sheet. Is that possible?
    LVL 1

    Author Comment

    Oh now i see it does work but it wrote the values in row 64 while it should write in row 2
    then 3 then 4.... etc
    LVL 1

    Accepted Solution

    i fixed it using
        With Workbooks(WorkbookName).Sheets("DividedPD's")
        x = .Cells(Rows.Count, "A").End(xlUp).Row + 1
        .Range("A" & x).Value = TextBox1
        .Range("B" & x).Value = TextBox2
        .Range("C" & x).Value = TextBox3
        .Range("D" & x).Value = TextBox5
        .Range("E" & x).Value = TextBox6
        .Range("F" & x).Value = TextBox7
        .Range("G" & x).Value = TextBox9
        .Range("H" & x).Value = TextBox10
        .Range("I" & x).Value = TextBox11

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
    Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
    The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
    This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now