• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 431
  • Last Modified:

excel vba write from userform to sheet

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:)
  • 3
1 Solution
MarkVrenkenAuthor Commented:
Oh and ps i'd rather not activate the sheet. Is that possible?
MarkVrenkenAuthor Commented:
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
MarkVrenkenAuthor Commented:
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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now