[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 426
  • 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
    
    UserForm_Initialize
End Sub

Open in new window


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

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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